Skip to content

SqliteJournal

Defined in: src/persistence/journals/SqliteJournal.ts:54

Journal backed by SQLite — zero-dependency, single-file persistence.

Works on Bun (bun:sqlite) and Node.js (better-sqlite3) via the SqliteDriver abstraction in src/runtime/sqlite/. Both backends share the same prepared-statement + transaction shape, so the journal code itself is unchanged across runtimes.

Construction is lazy: the native DB is opened on the first append / read / highestSeq / delete / persistenceIds call. This keeps new SqliteJournal({ path }) sync-friendly (matches the pre-abstraction shape) while still supporting the async driver-resolution flow Node requires.

new SqliteJournal(options?): SqliteJournal

Defined in: src/persistence/journals/SqliteJournal.ts:71

SqliteJournalOptions = {}

SqliteJournal

readonly events: JournalEventBus

Defined in: src/persistence/journals/SqliteJournal.ts:65

In-process event bus — published-to inside append so the query layer can do sub-poll-interval push delivery in the same process. Cross-process subscribers (separate Bun/Node instance reading the same SQLite file) still need to poll; that’s the inherent limit of in-process notifications.

Journal.events

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

Defined in: src/persistence/journals/SqliteJournal.ts:76

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/SqliteJournal.ts:188

Best-effort teardown; idempotent.

Promise<void>

Journal.close


delete(pid, toSeq): Promise<void>

Defined in: src/persistence/journals/SqliteJournal.ts:170

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/SqliteJournal.ts:164

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

string

Promise<number>

Journal.highestSeq


persistenceIds(): Promise<string[]>

Defined in: src/persistence/journals/SqliteJournal.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/SqliteJournal.ts:133

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