SqliteQuery
Defined in: src/persistence/query/SqliteQuery.ts:50
SQLite-backed query. Inherits the per-pid read path from
InMemoryQuery (which delegates straight to Journal.read)
and overrides the tag path with an indexed JOIN against the
${eventsTable}_tags join table that SqliteJournal maintains.
Index shape. The journal’s tags table has primary key
(tag, timestamp, persistence_id, sequence_nr), so a
WHERE tag = ? AND timestamp >= ? filter walks a contiguous
range of the index — bounded cost per query no matter how big
the events table grows. We then JOIN to events to pull the
payload + the original CSV tags column.
Backwards-compat. SqliteJournal upgrades existing v0
databases (CSV-only, no join table) by backfilling the join
table on init() — see SqliteJournal.backfillTagsTableIfNeeded.
From the query layer’s POV the table is always present once the
journal is open.
Multi-tag filters. The TagFilter operators (all / any /
not) are pushed into SQL with one of three strategies:
- At least one
alltag → walk the join-table forall[0], JS-refine the rest of the filter againstevents.tags. The SQL is the same as the single-tag fast path; only the JS step is wider. - No
all, butanyis non-empty → walk the join-table witht.tag IN (?, ?, …)(DISTINCT to dedupe events tagged with more than one of the listed values), JS-refine fornot. - Only
not(or empty filter) → fall back to the inherited InMemoryQuery scan path, which iterates persistence ids and reads each one. Less efficient, but only-notqueries don’t have a selective index to use anyway.
Extends
Section titled “Extends”Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new SqliteQuery(
sqlite):SqliteQuery
Defined in: src/persistence/query/SqliteQuery.ts:65
Parameters
Section titled “Parameters”sqlite
Section titled “sqlite”Returns
Section titled “Returns”SqliteQuery
Overrides
Section titled “Overrides”Methods
Section titled “Methods”currentEventsByPersistenceId()
Section titled “currentEventsByPersistenceId()”currentEventsByPersistenceId<
E>(pid,fromSeq,toSeq?):Promise<PersistentEvent<E>[]>
Defined in: src/persistence/query/InMemoryQuery.ts:41
One-shot read of every event for persistenceId whose
sequenceNr >= fromSeq (and <= toSeq if given). Resolves
once with the events known at call time.
Type Parameters
Section titled “Type Parameters”E
Parameters
Section titled “Parameters”string
fromSeq
Section titled “fromSeq”number
toSeq?
Section titled “toSeq?”number
Returns
Section titled “Returns”Promise<PersistentEvent<E>[]>
Inherited from
Section titled “Inherited from”InMemoryQuery.currentEventsByPersistenceId
currentEventsByTag()
Section titled “currentEventsByTag()”currentEventsByTag<
E>(filter,fromOffset):Promise<TaggedEvent<E>[]>
Defined in: src/persistence/query/SqliteQuery.ts:69
One-shot read of every event matching filter whose offset is
>= fromOffset. See TagFilter for the operator semantics.
Type Parameters
Section titled “Type Parameters”E
Parameters
Section titled “Parameters”filter
Section titled “filter”fromOffset
Section titled “fromOffset”Returns
Section titled “Returns”Promise<TaggedEvent<E>[]>
Overrides
Section titled “Overrides”InMemoryQuery.currentEventsByTag
currentPersistenceIds()
Section titled “currentPersistenceIds()”currentPersistenceIds():
Promise<string[]>
Defined in: src/persistence/query/InMemoryQuery.ts:107
Snapshot of every persistence id known to the journal. Resolves
once. Useful for fan-out projections that subscribe to one
stream per id; pair with eventsByPersistenceId for the
continuous read.
Returns
Section titled “Returns”Promise<string[]>
Inherited from
Section titled “Inherited from”InMemoryQuery.currentPersistenceIds
eventsByPersistenceId()
Section titled “eventsByPersistenceId()”eventsByPersistenceId<
E>(pid,fromSeq,options?):AsyncIterable<PersistentEvent<E>>
Defined in: src/persistence/query/InMemoryQuery.ts:47
Live stream of every event for persistenceId whose
sequenceNr >= fromSeq. Past events are emitted first
(chronological by sequenceNr), then new events as they are
appended. The stream never completes on its own — break out of
the loop or call return() on the iterator to stop polling.
Type Parameters
Section titled “Type Parameters”E
Parameters
Section titled “Parameters”string
fromSeq
Section titled “fromSeq”number
options?
Section titled “options?”LiveQueryOptions = {}
Returns
Section titled “Returns”AsyncIterable<PersistentEvent<E>>
Inherited from
Section titled “Inherited from”InMemoryQuery.eventsByPersistenceId
eventsByTag()
Section titled “eventsByTag()”eventsByTag<
E>(filter,fromOffset,options?):AsyncIterable<TaggedEvent<E>>
Defined in: src/persistence/query/InMemoryQuery.ts:84
Live stream of every event matching filter whose offset is
>= fromOffset. Yields events ordered by (timestamp, persistenceId, sequenceNr). See Offset for offset
semantics — the stream emits the offset alongside the event so
the consumer can persist progress.
filter accepts either a single tag string (back-compat shortcut
for { all: [tag] }) or a TagFilter object that combines
all (intersect), any (union), and not (exclusion) operators.
Type Parameters
Section titled “Type Parameters”E
Parameters
Section titled “Parameters”filter
Section titled “filter”fromOffset
Section titled “fromOffset”options?
Section titled “options?”LiveQueryOptions = {}
Returns
Section titled “Returns”AsyncIterable<TaggedEvent<E>>