SqlEventJournal unstable
SQL-backed event journal with per-remote upload checkpoints.
Constructors
Creates an EventJournal backed by a SQL database.
Details
Maintains entryTable, ${entryTable}_sequence, ${entryTable}_sources,
${remotesTable}_checkpoints and remoteCursorsTable (default
${remotesTable}_cursors) using the configured SqlClient.
Gotchas
Creating or migrating the schema requires a writable connection. Migrated databases can be reopened read-only.
Journals from earlier releases keep one remotesTable row per entry per
remote. Opening one replaces those rows with entry sources and drops the
table; an entry known to several remotes keeps one of them as its source.
Upload acknowledgements do not advance past unseen entries.
Signature
declare function make(options?: { readonly entryTable?: string; readonly remoteCursorsTable?: 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 entriesById: (ids: readonly Array<EntryId>) => Effect<readonly Array<Entry | undefined>, 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: (entries: readonly Array<{ 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>; readonly writeMany: <A, E, R>(options: { readonly effect: (entries: readonly [Entry, Entry]) => Effect<A, E, R>; readonly entries: readonly [{ readonly event: string; readonly payload: Uint8Array; readonly primaryKey: string; }, { readonly event: string; readonly payload: Uint8Array; readonly primaryKey: string; }]; }) => Effect<A, EventJournalError | E, R>; readonly writeRemoteAcks: (options: { readonly acks: readonly Array<RemoteAck>; readonly firstSequence?: number; readonly remoteId: RemoteId; }) => Effect<void, EventJournalError>;}, SqlError, SqlClient>Layers
Provides a SQL-backed EventJournal from an existing SqlClient service.
Gotchas
Creating or migrating the schema requires a writable connection.
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 remoteCursorsTable?: string; readonly remotesTable?: string;}): Layer<EventJournal, SqlError, SqlClient>