Skip to content

createClientPGlite

createClientPGlite(store, options?): Promise<ClientPGlite>

Defined in: packages/client/src/index.ts:528

Create the raw local PGlite store the sync client runs on — the SAME PGlite.create call createSyncClient makes internally (the electric + live extensions, pre-warmed boot-asset consumption, and the boot pglite.create rail stamp), extracted so exactly one implementation exists and a host can create the store EAGERLY on an earlier screen. Hand the returned (still-pending) instance to CreateSyncClientOptions.precreatedPglite: the client then owns schema exec, prepare hooks, journal recovery, and registry reconciliation, exactly as its own storePath path does.

Takes a plain store path (ADR-0036), never a storage URL — the backend is DERIVED from the engine home (capability-selected opfs-repacked with IndexedDB fallback in a browser, or the filesystem on Bun/Node); a scheme-bearing path throws InvalidStorePathError. Also accepts the testing helper’s output (createClientPGlite(memoryStoreForTests("x"))) so a test can mint a memory store without naming a backend.

The instance is deliberately schemaless — the registry-derived local schema is role/registry dependent, so it is applied post-create by createSyncClient. The eager create buys only the expensive initdb (+ persistent-store open), which is the dominant cold-boot cost once the WASM is pre-warmed.

bootAssets is the pre-warmed WASM/fs bundle (see CreateSyncClientOptions.pgliteBootAssets); a rejected warm is caught to undefined, so PGlite falls back to loading its own assets — never a failure.

StorePathInput

CreateClientPGliteOptions

Promise<ClientPGlite>