SqlEventJournal
SQL-backed persistence for the unstable event-log journal.
This module implements EventJournal on top of a SqlClient. It stores event
entries as encoded bytes and stores per-remote sequence metadata in separate
tables, giving event-log programs a durable journal that can be replayed after
restart and synchronized with remote journals.
Constructors
Creates an EventJournal backed by a SQL database.
Details
The constructor creates the entry and remote metadata tables when needed,
persists local and remote entries, and uses the configured SqlClient.
Signature
declare function make(options?: { readonly entryTable?: string; readonly remotesTable?: string;}): Effect<{ readonly changes: Effect<Subscription<Entry>, never, Scope>; readonly destroy: Effect<void, EventJournalError>; readonly entries: Effect<readonly Array<Entry>, EventJournalError>; readonly nextRemoteSequence: (remoteId: RemoteId) => Effect<number, EventJournalError>; readonly withLock: (storeId: StoreId) => <A, E, R>(effect: Effect<A, E, R>) => Effect<A, E, R>; readonly withRemoteUncommited: <A, E, R>(remoteId: RemoteId, f: (entries: readonly [Entry, Entry]) => Effect<A, E, R>) => Effect<Option<A>, EventJournalError | E, R>; readonly write: <A, E, R>(options: { readonly effect: (entry: Entry) => Effect<A, E, R>; readonly event: string; readonly payload: Uint8Array; readonly primaryKey: string; }) => Effect<A, EventJournalError | E, R>; readonly writeFromRemote: (options: { readonly compact?: (uncommitted: readonly Array<RemoteEntry>) => Effect<readonly Array<Entry>, EventJournalError>; readonly effect: (options: { readonly conflicts: readonly Array<Entry>; readonly entry: Entry; }) => Effect<void, EventJournalError>; readonly entries: readonly Array<RemoteEntry>; readonly remoteId: RemoteId; }) => Effect<{ readonly duplicateEntries: readonly Array<Entry>; }, EventJournalError>;}, SqlError, SqlClient>Layers
Provides EventJournal using the SQL-backed implementation created by
make.
When to use
Use when composing a Layer graph that should provide a persistent SQL-backed
EventJournal from an existing SqlClient service.
Details
The layer delegates to make(options), so the same optional entryTable and
remotesTable settings are used and construction requires SqlClient and
may fail with SqlError.
Gotchas
Layer construction performs the same minimal CREATE TABLE IF NOT EXISTS
setup as make; manage indexes and schema migrations outside this layer when
your SQL schema needs more than the built-in tables.
See
- make for constructing the SQL-backed service directly
- EventJournal.layerMemory for an in-memory
EventJournallayer - EventJournal.layerIndexedDb for an IndexedDB-backed
EventJournallayer
Signature
declare function layer(options?: { readonly entryTable?: string; readonly remotesTable?: string;}): Layer<EventJournal, SqlError, SqlClient>