Pular para o conteúdo
Português (BR)

PostgresJournal

Este conteúdo não está disponível em sua língua ainda.

Defined in: src/persistence/journals/PostgresJournal.ts:50

Journal backed by PostgreSQL via the pg (node-postgres) driver.

Mirrors SqliteJournal’s shape — an events table keyed on (persistence_id, sequence_nr) plus a tags join table for indexed tag queries — using Postgres types and $1 bind parameters.

Optimistic concurrency: append runs SELECT MAX(sequence_nr) and the INSERTs inside one transaction; a racing writer that slips between the read and the insert trips the primary-key unique constraint (SQLSTATE 23505), which is translated to JournalConcurrencyError as a backstop. Construction is lazy — the pool opens and tables are created on the first call.

No in-process event bus: Postgres is a cross-process backend (like Cassandra), so the events field is left undefined and the query layer falls back to polling. (A LISTEN/NOTIFY bus is a possible future enhancement.)

new PostgresJournal(options?): PostgresJournal

Defined in: src/persistence/journals/PostgresJournal.ts:60

PostgresJournalOptions = {}

PostgresJournal

append<E>(pid, events, expectedSeq, tags?): Promise<PersistentEvent<E>[]>

Defined in: src/persistence/journals/PostgresJournal.ts:69

Append events to the stream of pid, enforcing optimistic concurrency: the current highest sequence number MUST equal expectedSeq or the call throws JournalConcurrencyError. Returns the written events with their assigned sequence numbers.

E

string

readonly E[]

number

readonly string[]

Promise<PersistentEvent<E>[]>

Journal.append


close(): Promise<void>

Defined in: src/persistence/journals/PostgresJournal.ts:188

Best-effort teardown; idempotent.

Promise<void>

Journal.close


delete(pid, toSeq): Promise<void>

Defined in: src/persistence/journals/PostgresJournal.ts:167

Delete events up to and including toSeq — used when compacting past a snapshot.

string

number

Promise<void>

Journal.delete


highestSeq(pid): Promise<number>

Defined in: src/persistence/journals/PostgresJournal.ts:158

Current highest sequence number for pid — 0 if no events exist.

string

Promise<number>

Journal.highestSeq


persistenceIds(): Promise<string[]>

Defined in: src/persistence/journals/PostgresJournal.ts:182

Persistence IDs currently known to the journal (useful for projections).

Promise<string[]>

Journal.persistenceIds


read<E>(pid, fromSeq, toSeq?): Promise<PersistentEvent<E>[]>

Defined in: src/persistence/journals/PostgresJournal.ts:134

Return events in (fromSeq, …, toSeq] order. toSeq defaults to the current highest sequence number. Inclusive bounds — fromSeq is the first event returned, not the “after” cursor.

E

string

number

number

Promise<PersistentEvent<E>[]>

Journal.read