Background
PostgresKvStore requires a running PostgreSQL server. For local development, tests, and small single-process deployments, PGlite (PostgreSQL compiled to WebAssembly, @electric-sql/pglite) provides the same SQL without a server and runs on Node.js, Bun, and Deno.
I propose PgliteKvStore in @fedify/pglite. It takes a PGlite client and is otherwise identical to PostgresKvStore, sharing its table schema and default table name (the options only omit unlogged):
const pg = new PGlite("./data/fedify");
const federation = createFederation({
kv: new PgliteKvStore(pg),
});
Verified
Every SQL statement in kv.ts runs unchanged on PGlite 0.5.8 (PostgreSQL 18.3) under Deno 2.9.5, Node.js 22.23.1, and Bun 1.2.22, including text[]/jsonb/interval parameters.
Differences to handle:
- A bare JavaScript string bound to
jsonb fails; values must always be JSON.stringify’d and cast from text.
- Deno needs
--allow-read (and --allow-write for on-disk data) to load the WebAssembly module.
- One PGlite instance per data directory; data is not shared across processes.
Work
- Add
PgliteKvStore in a new @fedify/pglite package.
- Add
testKvStore(), a KvStore conformance suite, to @fedify/testing and run it against MemoryKvStore and PgliteKvStore.
How about PgliteMessageQueue?
Not provided, since separate instances do not share PostgreSQL's usual process and shared-memory state, a queue could not distribute work across processes.
Background
PostgresKvStorerequires a running PostgreSQL server. For local development, tests, and small single-process deployments, PGlite (PostgreSQL compiled to WebAssembly,@electric-sql/pglite) provides the same SQL without a server and runs on Node.js, Bun, and Deno.I propose
PgliteKvStorein@fedify/pglite. It takes aPGliteclient and is otherwise identical toPostgresKvStore, sharing its table schema and default table name (the options only omitunlogged):Verified
Every SQL statement in
kv.tsruns unchanged on PGlite 0.5.8 (PostgreSQL 18.3) under Deno 2.9.5, Node.js 22.23.1, and Bun 1.2.22, includingtext[]/jsonb/intervalparameters.Differences to handle:
jsonbfails; values must always beJSON.stringify’d and cast fromtext.--allow-read(and--allow-writefor on-disk data) to load the WebAssembly module.Work
PgliteKvStorein a new@fedify/pglitepackage.testKvStore(), aKvStoreconformance suite, to@fedify/testingand run it againstMemoryKvStoreandPgliteKvStore.How about
PgliteMessageQueue?Not provided, since separate instances do not share PostgreSQL's usual process and shared-memory state, a queue could not distribute work across processes.