@godspeedai/cognate-store-postgres

中文文档
0.10.0发布于 2026/11/16Apache-2.0ES Module构建来源已验证近 30 天下载 3626

Authoritative DurableStore on PostgreSQL (spec §13); multi-process writers.

原始使用文档
文档目录6 节
  1. Installation
  2. Quick start
  3. Multi-process behavior
  4. Notes and limitations
  5. Related packages
  6. License

@godspeedai/cognate-store-postgres

Durable, transactional event storage for Cognate applications on PostgreSQL. Multiple processes write the same database safely: position order equals commit order, outbox claims are atomic across workers, and projection folds serialize by checkpoint.

When to use this package: apps that need more than one runtime process (or host) against one authoritative store, or a database you can back up, monitor, and operate with normal PostgreSQL tooling. Use @godspeedai/cognate-store-sqlite for a zero-dependency single-process file, or @godspeedai/cognate-store-memory for tests. All three implement the same @godspeedai/cognate-events store contract, so an app can switch stores with one line.

Installation

bun add @godspeedai/cognate-store-postgres

Requires Bun >= 1.4.0 and a PostgreSQL server (PostgreSQL 14 or newer; PostgreSQL 18 is what the test matrix runs). Driver: postgres (pure JavaScript, no native build).

Quick start

import { openPostgresStore } from "@godspeedai/cognate-store-postgres";

const handle = await openPostgresStore({
  url: "postgres://postgres:[email protected]:5432/postgres",
  schema: "myapp", // tables live in one schema; create one per app or per test
});

const store = handle.store; // a DurableStore — pass to createRuntime or use directly
await store.commit({
  appends: [{ streamId: "case-1", expectedVersion: 0, events: [{ /* NewEvent */ }] }],
});
await handle.close();

Multi-process behavior

  • Every commit that appends events takes a short lock on one position-counter row, so store positions are allocated exactly in commit order across processes; record writes, outbox claims, and projection folds do not queue behind it.
  • onCommitted listeners receive local commits immediately and other processes' commits through LISTEN/NOTIFY plus a cursor-based catch-up over the event log (with a small poll safety net), so a lost notification only delays delivery; it can never skip it.
  • claimOutbox uses FOR UPDATE SKIP LOCKED: concurrent workers claim disjoint work with no waiting.
  • Projection checkpoints are guarded by a row lock plus compare-and-swap, so two runners on the same projection never double-apply a batch.

Notes and limitations

  • Tables live in the schema you name (default cognate); the schema is created if absent, and schema migrations are versioned and serialized across processes.
  • Durability follows PostgreSQL's defaults (synchronous_commit=on, fsync=on); the store does not relax them.
  • erasePayload deletes the payload and keeps a tombstone envelope, as the store contract requires. PostgreSQL MVCC keeps the deleted bytes in dead tuples and WAL until autovacuum and WAL recycling; run VACUUM <schema>.payloads (or just db-vacuum) when an operator needs the physical pages reclaimed promptly. WAL segments recycle once checkpoints pass max_wal_size, so erased bytes in WAL age out on the same schedule — treat backups and archived WAL as retaining erased content per your retention policy.
  • Ordering comparisons (record ids, projection keys) use byte order (COLLATE "C"), matching the other stores' code-point ordering.

License

Apache-2.0

版本与发布记录

@godspeedai/cognate-store-postgres 共发布 17 个版本,首次发布于 2026/10/12;过去 12 个月发布了 17 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.10.0latest2026/11/16今天
0.9.22026/11/152 天前
0.9.12026/11/143 天前
0.9.02026/11/0610 天前
0.8.02026/10/2720 天前
0.7.12026/10/2523 天前

关于 @godspeedai/cognate-store-postgres 的常见问题

@godspeedai/cognate-store-postgres 是什么?

Authoritative DurableStore on PostgreSQL (spec §13); multi-process writers.

如何安装 @godspeedai/cognate-store-postgres?

在项目目录运行 npm install @godspeedai/cognate-store-postgres,或使用 pnpm add / yarn add / bun add。

@godspeedai/cognate-store-postgres 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/godspeedai__cognate-store-postgres 是否存在。

@godspeedai/cognate-store-postgres 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@godspeedai/cognate-store-postgres 可以商用吗?

@godspeedai/cognate-store-postgres 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@godspeedai/cognate-store-postgres 的下载量有多少?

根据 npm 官方下载统计,@godspeedai/cognate-store-postgres 在 2026/10/17 – 2026/11/15 这 30 天内被下载 3,626 次,日均约 121 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@godspeedai/cognate-store-postgres 还在维护吗?

最新版本 0.10.0 发布于 2026/11/16(今天);至今共发布 17 个版本,其中过去 12 个月发布了 17 个;首次发布于 2026/10/12。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。