@elysiumjs/moirai-drizzle

中文文档
0.4.1发布于 2026/11/12Apache-2.0TypeScriptES Module近 30 天下载 3770

Postgres stores for @elysiumjs/moirai through Drizzle ORM: idempotency keys, outbox, inbox and advisory locks.

此软件包已被标记为弃用

Replaced by @elysiumjs/drizzle.

原始使用文档
文档目录3 节
  1. Installation
  2. Tables
  3. Stores

@elysiumjs/moirai-drizzle

Postgres stores for @elysiumjs/moirai, through Drizzle ORM and the connections of @elysiumjs/mnemosyne-drizzle. They write in the transaction of the action, so an idempotency record, the outbox rows and the stored events commit with the data.

Installation

bun add @elysiumjs/moirai @elysiumjs/moirai-drizzle @elysiumjs/mnemosyne-drizzle

Tables

import { moiraiTables } from '@elysiumjs/moirai-drizzle';

// In the Drizzle schema, so that migration:generate creates them.
export const billing = moiraiTables('billing');

moiraiTables(schema?, options?) builds the idempotency_keys, outbox, inbox, events and projections tables, in a Postgres schema when one is given (one set of tables per domain schema, for example).

With { partitioned: true }, events is partitioned by range of occurred_at and outbox by range of created_at. Their primary and unique keys then include that column, and migration:generate creates them with PARTITION BY RANGE. The partitions are up to the app: create them in a migration hook, or add them to the migration that creates the table with DrizzleTable.afterCreate() from @elysiumjs/mnemosyne-drizzle:

import { DrizzleTable } from '@elysiumjs/mnemosyne-drizzle';

const tables = moiraiTables('billing', { partitioned: true });

export const billing = {
    ...tables,
    events: DrizzleTable.define(
        DrizzleTable.afterCreate(
            ({ qualified }) => `CREATE TABLE "billing"."events_default" PARTITION OF ${qualified} DEFAULT`
        )
    )(tables.events)
};

Stores

import { MoiraiModule } from '@elysiumjs/moirai';
import {
    DrizzleEventStore,
    DrizzleIdempotencyStore,
    DrizzleInboxStore,
    DrizzleOutboxStore,
    DrizzleProjectionStorage,
    PgAdvisoryLock
} from '@elysiumjs/moirai-drizzle';

MoiraiModule.with({
    idempotency: () => new DrizzleIdempotencyStore({ table: billing.idempotencyKeys }),
    outbox: () => new DrizzleOutboxStore({ table: billing.outbox }),
    inbox: () => new DrizzleInboxStore({ table: billing.inbox }),
    lock: () => new PgAdvisoryLock(),
    events: () => new DrizzleEventStore({ table: billing.events }),
    projections: () => new DrizzleProjectionStorage({ table: billing.projections })
});
  • DrizzleIdempotencyStore keeps the response of an idempotent action per key.
  • DrizzleOutboxStore claims due rows with FOR UPDATE SKIP LOCKED, so that several relays never take the same row.
  • DrizzleInboxStore records the messages a consumer has processed.
  • DrizzleEventStore keeps the event streams of aggregates. An append locks each stream it writes with a transaction advisory lock and checks that the stream ends right before the first appended version, so a stale writer gets a ConcurrencyConflictError even when the unique key of the table spans more columns, such as a partition key. Postgres gives each event its position and the id of the transaction that wrote it (transaction_id).
  • DrizzleProjectionStorage resets the tables of the models of a projection (DrizzleModels or Drizzle tables) with DELETE in the rebuild's transaction, so readers see the rows until it commits, and keeps the version each projection was built with.
  • PgAdvisoryLock serializes the actions that share a serializeBy key with a transaction advisory lock.

Each store takes connection, the name of a mnemosyne-drizzle connection, which defaults to default. A store's table needs the columns of the matching table in moiraiTables, and may add others: it can live in a domain's own pgSchema and have another primary key, such as a composite one. StoreTable<T> is the type it accepts.

版本与发布记录

@elysiumjs/moirai-drizzle 共发布 21 个版本,首次发布于 2026/11/07;过去 12 个月发布了 21 个版本。

版本发布日期距今
0.4.1latest2026/11/121 天前
0.4.02026/11/121 天前
0.3.62026/11/121 天前
0.3.52026/11/112 天前
0.3.42026/11/112 天前
0.3.32026/11/112 天前

关于 @elysiumjs/moirai-drizzle 的常见问题

@elysiumjs/moirai-drizzle 是什么?

Postgres stores for @elysiumjs/moirai through Drizzle ORM: idempotency keys, outbox, inbox and advisory locks.注意:该包已被作者标记为弃用——Replaced by @elysiumjs/drizzle.

如何安装 @elysiumjs/moirai-drizzle?

在项目目录运行 npm install @elysiumjs/moirai-drizzle,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@elysiumjs/core(^0.24.1)、@elysiumjs/moirai(^0.8.1)、@elysiumjs/mnemosyne-drizzle(^0.9.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@elysiumjs/moirai-drizzle 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@elysiumjs/moirai-drizzle 支持 ESM 还是 CommonJS?

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

@elysiumjs/moirai-drizzle 可以商用吗?

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

@elysiumjs/moirai-drizzle 的下载量有多少?

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

@elysiumjs/moirai-drizzle 还在维护吗?

最新版本 0.4.1 发布于 2026/11/12(1 天前);至今共发布 21 个版本,其中过去 12 个月发布了 21 个;首次发布于 2026/11/07。作者已将其标记为弃用,新项目建议寻找替代方案。