Skip to content

Commit b6fdaec

Browse files
authored
Merge pull request #1020 from 2chanhaeng/pglite
Add `@fedify/pglite` with `PgliteKvStore`
2 parents b10aff9 + 41cebe9 commit b6fdaec

25 files changed

Lines changed: 1343 additions & 221 deletions

‎.github/CODEOWNERS‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
/packages/amqp/ @dahlia
8181
/packages/denokv/ @dahlia @2chanhaeng
8282
/packages/mysql/ @dahlia
83+
/packages/pglite/ @dahlia @2chanhaeng
8384
/packages/postgres/ @dahlia @2chanhaeng
8485
/packages/redis/ @dahlia @2chanhaeng
8586
/packages/sqlite/ @dahlia @2chanhaeng

‎CHANGES.md‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,17 @@ To be released.
258258
explicit recovery for unobservable dead-letter failures.
259259
[[#930], [#934]]
260260

261+
### @fedify/pglite
262+
263+
- Added the `@fedify/pglite` package with `PgliteKvStore`, a `KvStore` backed
264+
by an embedded PGlite database. It accepts a caller-created PGlite instance
265+
and is intended for a single PGlite instance in a single runtime isolate; a
266+
message queue is not provided because PGlite does not share data between
267+
processes. [[#1018], [#1020] by ChanHaeng Lee\]
268+
269+
[#1018]: https://github.com/fedify-dev/fedify/issues/1018
270+
[#1020]: https://github.com/fedify-dev/fedify/issues/1020
271+
261272
### @fedify/postgres
262273

263274
- Added `PostgresKvStore.cas()`, including atomic creation, replacement, and
@@ -311,6 +322,9 @@ To be released.
311322

312323
### @fedify/testing
313324

325+
- Added `testKvStore()`, a conformance test suite for `KvStore`
326+
implementations, complementing `testMessageQueue()`.
327+
[[#1018], [#1020] by ChanHaeng Lee\]
314328
- Fixed the CommonJS testing utilities build so it no longer requires
315329
`@js-temporal/polyfill` at runtime. The build now bundles
316330
`temporal-polyfill`, while type declarations rely on the standard
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
- Added the `@fedify/pglite` package with `PgliteKvStore`, a `KvStore` backed
2+
by an embedded PGlite database. It accepts a caller-created PGlite instance
3+
and is intended for a single PGlite instance in a single runtime isolate; a
4+
message queue is not provided because PGlite does not share data between
5+
processes. [[#1018], [#1020] by ChanHaeng Lee]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
- Added `testKvStore()`, a conformance test suite for `KvStore`
2+
implementations, complementing `testMessageQueue()`.
3+
[[#1018], [#1020] by ChanHaeng Lee]

‎cspell.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
"optique",
8787
"oxlint",
8888
"oxlintrc",
89+
"pglite",
8990
"phensley",
9091
"Pico",
9192
"Pixelfed",

‎deno.json‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"./packages/mysql",
2222
"./packages/netlify",
2323
"./packages/nuxt",
24+
"./packages/pglite",
2425
"./packages/postgres",
2526
"./packages/redis",
2627
"./packages/relay",
@@ -45,6 +46,7 @@
4546
"imports": {
4647
"@cloudflare/workers-types": "npm:@cloudflare/workers-types@^4.20260511.1",
4748
"@david/dax": "jsr:@david/dax@^0.46.1",
49+
"@electric-sql/pglite": "npm:@electric-sql/pglite@^0.5.8",
4850
"@fxts/core": "npm:@fxts/core@^1.21.1",
4951
"@hongminhee/localtunnel": "jsr:@hongminhee/localtunnel@^0.3.0",
5052
"@js-temporal/polyfill": "npm:@js-temporal/polyfill@^0.5.1",
@@ -61,6 +63,8 @@
6163
"@optique/core": "jsr:@optique/core@^1.1.0",
6264
"@optique/discover": "jsr:@optique/discover@^1.1.0",
6365
"@optique/run": "jsr:@optique/run@^1.1.0",
66+
"@solidjs/start/middleware": "npm:@solidjs/start@^1.3.0/middleware",
67+
"@solidjs/start/server": "npm:@solidjs/start@^1.3.0/server",
6468
"@standard-schema/spec": "jsr:@standard-schema/spec@^1.1.0",
6569
"@std/assert": "jsr:@std/assert@^1.0.13",
6670
"@std/async": "jsr:@std/async@^1.0.13",
@@ -69,11 +73,10 @@
6973
"@std/path": "jsr:@std/path@^1.0.6",
7074
"@std/testing": "jsr:@std/testing@^0.224.0",
7175
"@std/yaml": "jsr:@std/yaml@^1.0.8",
76+
"@types/emscripten": "npm:@types/emscripten@^1.41.1",
7277
"@types/node": "npm:@types/node@^22.16.0",
7378
"amqplib": "npm:amqplib@^0.10.9",
7479
"asn1js": "npm:asn1js@^3.0.10",
75-
"@solidjs/start/middleware": "npm:@solidjs/start@^1.3.0/middleware",
76-
"@solidjs/start/server": "npm:@solidjs/start@^1.3.0/server",
7780
"astro": "npm:astro@^7.0.0",
7881
"byte-encodings": "npm:byte-encodings@^1.0.11",
7982
"chalk": "npm:chalk@^5.6.2",

‎deno.lock‎

Lines changed: 31 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎docs/manual/kv.md‎

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,74 @@ const federation = createFederation<void>({
306306

307307
[`PostgresKvStore`]: https://jsr.io/@fedify/postgres/doc/kv/~/PostgresKvStore
308308

309+
### [`PgliteKvStore`]
310+
311+
*This API is available since Fedify 2.4.0.*
312+
313+
To use the [`PgliteKvStore`], install the *@fedify/pglite* package and PGlite:
314+
315+
::: code-group
316+
317+
~~~~ bash [Deno]
318+
deno add jsr:@fedify/pglite npm:@electric-sql/pglite
319+
~~~~
320+
321+
~~~~ bash [npm]
322+
npm add @fedify/pglite @electric-sql/pglite
323+
~~~~
324+
325+
~~~~ bash [pnpm]
326+
pnpm add @fedify/pglite @electric-sql/pglite
327+
~~~~
328+
329+
~~~~ bash [Yarn]
330+
yarn add @fedify/pglite @electric-sql/pglite
331+
~~~~
332+
333+
~~~~ bash [Bun]
334+
bun add @fedify/pglite @electric-sql/pglite
335+
~~~~
336+
337+
:::
338+
339+
[`PgliteKvStore`] uses an embedded PGlite database without requiring a
340+
PostgreSQL server. It uses the same schema and default table name as
341+
[`PostgresKvStore`], so data can be migrated to PostgreSQL without converting
342+
the key–value records.
343+
344+
Best for
345+
: Development and testing, single-process deployments, and embedded or
346+
desktop applications that need PostgreSQL-compatible storage without a
347+
PostgreSQL server.
348+
349+
Pros
350+
: No server installation, PostgreSQL-compatible SQL, and the same schema as
351+
[`PostgresKvStore`].
352+
353+
Cons
354+
: Only one process and PGlite instance can open a data directory, data are
355+
not shared between processes, and horizontal scaling is not supported.
356+
357+
~~~~ typescript twoslash
358+
import { PGlite } from "@electric-sql/pglite";
359+
import { createFederation } from "@fedify/fedify";
360+
import { PgliteKvStore } from "@fedify/pglite";
361+
362+
const pg = new PGlite("./data/fedify");
363+
const federation = createFederation<void>({
364+
kv: new PgliteKvStore(pg),
365+
// ... other options
366+
});
367+
~~~~
368+
369+
> [!WARNING]
370+
> The caller owns the PGlite instance and must close it during application
371+
> shutdown after pending store operations finish. Do not open the same data
372+
> directory from multiple worker processes. Use one PGlite instance per data
373+
> directory and runtime isolate.
374+
375+
[`PgliteKvStore`]: https://jsr.io/@fedify/pglite/doc/kv/~/PgliteKvStore
376+
309377
### [`MysqlKvStore`]
310378

311379
*This API is available since Fedify 2.1.0.*

0 commit comments

Comments
 (0)