Skip to content

Add @fedify/pglite with PgliteKvStore #1018

Description

@2chanhaeng

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

component/kvKey–value store relateddriver/pglitePGlite driver (@fedify/pglite)

Fields

Priority

None yet

Effort

None yet

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions