PostgresJournal
Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.
Defined in: src/persistence/journals/PostgresJournal.ts:18
Journal backed by PostgreSQL via the pg (node-postgres) driver.
The behaviour lives in RelationalJournal; this class supplies the Postgres
dialect ($n placeholders, ON CONFLICT, SQLSTATE 23505) and the pool.
Because the dialect matches on the SQLSTATE rather than message text, the
same store serves the Postgres-wire-compatible databases (CockroachDB,
YugabyteDB).
Construction is lazy — the pool opens and the tables are created on the first call.
Extends
Section titled “Extends”RelationalJournal
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new PostgresJournal(
options?):PostgresJournal
Defined in: src/persistence/journals/PostgresJournal.ts:19
Parameters
Section titled “Parameters”options?
Section titled “options?”Returns
Section titled “Returns”PostgresJournal
Overrides
Section titled “Overrides”RelationalJournal.constructor
Methods
Section titled “Methods”append()
Section titled “append()”append<
E>(persistenceId,events,expectedSeq,tags?):Promise<PersistentEvent<E>[]>
Defined in: src/persistence/relational/RelationalJournal.ts:102
Append events to the stream of persistenceId, 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.
Type Parameters
Section titled “Type Parameters”E
Parameters
Section titled “Parameters”persistenceId
Section titled “persistenceId”string
events
Section titled “events”readonly E[]
expectedSeq
Section titled “expectedSeq”number
readonly string[]
Returns
Section titled “Returns”Promise<PersistentEvent<E>[]>
Inherited from
Section titled “Inherited from”RelationalJournal.append
close()
Section titled “close()”close():
Promise<void>
Defined in: src/persistence/LazyStore.ts:66
Returns
Section titled “Returns”Promise<void>
Inherited from
Section titled “Inherited from”RelationalJournal.close
delete()
Section titled “delete()”delete(
persistenceId,toSeq):Promise<void>
Defined in: src/persistence/relational/RelationalJournal.ts:195
Delete events up to and including toSeq — used when compacting past
a snapshot. Only ever a prefix, so what survives is a suffix that
read still returns contiguously, and sequence numbers never rewind:
highestSeq keeps reporting the high-water mark afterwards.
Parameters
Section titled “Parameters”persistenceId
Section titled “persistenceId”string
number
Returns
Section titled “Returns”Promise<void>
Inherited from
Section titled “Inherited from”RelationalJournal.delete
highestSeq()
Section titled “highestSeq()”highestSeq(
persistenceId):Promise<number>
Defined in: src/persistence/relational/RelationalJournal.ts:186
Current highest sequence number for persistenceId — 0 if no events exist.
Parameters
Section titled “Parameters”persistenceId
Section titled “persistenceId”string
Returns
Section titled “Returns”Promise<number>
Inherited from
Section titled “Inherited from”RelationalJournal.highestSeq
persistenceIds()
Section titled “persistenceIds()”persistenceIds():
Promise<string[]>
Defined in: src/persistence/relational/RelationalJournal.ts:211
Persistence IDs currently known to the journal (useful for projections).
Returns
Section titled “Returns”Promise<string[]>
Inherited from
Section titled “Inherited from”RelationalJournal.persistenceIds
persistenceIdsPaginated()
Section titled “persistenceIdsPaginated()”persistenceIdsPaginated(
afterPersistenceId,limit):Promise<string[]>
Defined in: src/persistence/relational/RelationalJournal.ts:221
One ascending page of persistence ids: those strictly greater than
afterPersistenceId — all of them when it is undefined — capped at
limit. Returning fewer than limit means the journal is exhausted.
Optional on purpose. Not every store can enumerate ids in order:
DynamoDB reaches partition keys only through a full table scan, and
MongoDB’s distinct has no cursor. A journal without a sorted index
over its ids omits this, and the query layer falls back to
persistenceIds() plus an in-process slice — correct, just not cheaper
than the full list. Implement it wherever a sorted key exists; that is
what keeps currentPersistenceIdsPaginated from materialising a million
rows to hand back the first 256.
Which ascending order is the backend’s business. afterPersistenceId
is compared in the same order the page is sorted by, so Postgres’ collated
ORDER BY and SQLite’s byte-wise one are both fine — a paginated walk only
needs the order to be total and stable within one journal. What a
journal must not do is mix two orders across calls, which would make the
cursor skip ids.
Parameters
Section titled “Parameters”afterPersistenceId
Section titled “afterPersistenceId”string | undefined
number
Returns
Section titled “Returns”Promise<string[]>
Inherited from
Section titled “Inherited from”RelationalJournal.persistenceIdsPaginated
read()
Section titled “read()”read<
E>(persistenceId,fromSeq,toSeq?):Promise<PersistentEvent<E>[]>
Defined in: src/persistence/relational/RelationalJournal.ts:168
Return the events in [fromSeq, …, toSeq], ascending by sequence
number. toSeq defaults to the current highest sequence number.
Both bounds are inclusive — fromSeq is the first event returned,
not an “after” cursor.
Ordering and contiguity are part of the contract, and replay
enforces them (#122). Consecutive entries must differ by exactly
one, every sequenceNr must be a safe integer ≥ 1, and nothing may
fall outside the requested window. delete compacts a prefix,
never a hole in the middle, so a gap inside the returned slice can
only mean a defect — a missing ORDER BY, a half-written append, a
store someone else can write. replayState raises
JournalIntegrityError instead of folding it, because an actor
that recovers from a shuffled or holed stream reaches a state that
never existed and then fails every later persist with a
JournalConcurrencyError that has no visible cause.
Type Parameters
Section titled “Type Parameters”E
Parameters
Section titled “Parameters”persistenceId
Section titled “persistenceId”string
fromSeq
Section titled “fromSeq”number
toSeq?
Section titled “toSeq?”number
Returns
Section titled “Returns”Promise<PersistentEvent<E>[]>
Inherited from
Section titled “Inherited from”RelationalJournal.read
