Store
Defined in: packages/@livestore/livestore/src/store/store.ts:72
Extends
Section titled “Extends”- Class
Type Parameters
Section titled “Type Parameters”TSchema
Section titled “TSchema”TSchema extends LiveStoreSchema = Any
TContext
Section titled “TContext”TContext = { }
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new Store<
TSchema,TContext>(__namedParameters):Store<TSchema,TContext>
Defined in: packages/@livestore/livestore/src/store/store.ts:122
Parameters
Section titled “Parameters”__namedParameters
Section titled “__namedParameters”StoreOptions<TSchema, TContext>
Returns
Section titled “Returns”Store<TSchema, TContext>
Overrides
Section titled “Overrides”Inspectable.Class.constructor
Properties
Section titled “Properties”__eventSchema
Section titled “__eventSchema”
readonly__eventSchema:ForEventDefRecord<TSchema["_EventDefMapType"]>
Defined in: packages/@livestore/livestore/src/store/store.ts:116
activeQueries
Section titled “activeQueries”activeQueries:
ReferenceCountedSet<LiveQuery<any>>
Defined in: packages/@livestore/livestore/src/store/store.ts:113
RC-based set to see which queries are currently subscribed to
readonlyboot:Effect<void,UnexpectedError,Scope>
Defined in: packages/@livestore/livestore/src/store/store.ts:119
clientSession
Section titled “clientSession”clientSession:
ClientSession
Defined in: packages/@livestore/livestore/src/store/store.ts:76
commit()
Section titled “commit()”commit: {<
TCommitArg>(…list):void; (txn):void; <TCommitArg>(options, …list):void; (options,txn):void; }
Defined in: packages/@livestore/livestore/src/store/store.ts:644
Commit a list of events to the store which will immediately update the local database
and sync the events across other clients (similar to a git commit).
Call Signature
Section titled “Call Signature”<
TCommitArg>(…list):void
Type Parameters
Section titled “Type Parameters”TCommitArg
Section titled “TCommitArg”TCommitArg extends readonly PartialForSchema<TSchema>[]
Parameters
Section titled “Parameters”…TCommitArg
Returns
Section titled “Returns”void
Call Signature
Section titled “Call Signature”(
txn):void
Parameters
Section titled “Parameters”<TCommitArg>(…list) => void
Returns
Section titled “Returns”void
Call Signature
Section titled “Call Signature”<
TCommitArg>(options, …list):void
Type Parameters
Section titled “Type Parameters”TCommitArg
Section titled “TCommitArg”TCommitArg extends readonly PartialForSchema<TSchema>[]
Parameters
Section titled “Parameters”options
Section titled “options”StoreCommitOptions
…TCommitArg
Returns
Section titled “Returns”void
Call Signature
Section titled “Call Signature”(
options,txn):void
Parameters
Section titled “Parameters”options
Section titled “options”StoreCommitOptions
<TCommitArg>(…list) => void
Returns
Section titled “Returns”void
Examples
Section titled “Examples”store.commit(events.todoCreated({ id: nanoid(), text: 'Make coffee' }))You can call commit with multiple events to apply them in a single database transaction.
const todoId = nanoid()store.commit(  events.todoCreated({ id: todoId, text: 'Make coffee' }),  events.todoCompleted({ id: todoId }))For more advanced transaction scenarios, you can pass a synchronous function to commit which will receive a callback
to which you can pass multiple events to be committed in the same database transaction.
Under the hood this will simply collect all events and apply them in a single database transaction.
store.commit((commit) => {  const todoId = nanoid()  if (Math.random() > 0.5) {    commit(events.todoCreated({ id: todoId, text: 'Make coffee' }))  } else {    commit(events.todoCompleted({ id: todoId }))  }})When committing a large batch of events, you can also skip the database refresh to improve performance
and call store.manualRefresh() after all events have been committed.
const todos = [  { id: nanoid(), text: 'Make coffee' },  { id: nanoid(), text: 'Buy groceries' },  // ... 1000 more todos]for (const todo of todos) {  store.commit({ skipRefresh: true }, events.todoCreated({ id: todo.id, text: todo.text }))}store.manualRefresh()context
Section titled “context”context:
TContext
Defined in: packages/@livestore/livestore/src/store/store.ts:78
networkStatus
Section titled “networkStatus”
readonlynetworkStatus:Subscribable<{devtools: {latchClosed:boolean; };isConnected:boolean;timestampMs:number; },never,never>
Defined in: packages/@livestore/livestore/src/store/store.ts:97
Reactive connectivity updates emitted by the backing sync backend.
Example
Section titled “Example”import { Effect, Stream } from 'effect'
const status = await store.networkStatus.pipe(Effect.runPromise)
await store.networkStatus.changes.pipe(  Stream.tap((next) => console.log('network status update', next)),  Stream.runDrain,  Effect.scoped,  Effect.runPromise,)otel:
StoreOtel
Defined in: packages/@livestore/livestore/src/store/store.ts:79
reactivityGraph
Section titled “reactivityGraph”reactivityGraph:
ReactivityGraph
Defined in: packages/@livestore/livestore/src/store/store.ts:74
schema
Section titled “schema”schema:
LiveStoreSchema
Defined in: packages/@livestore/livestore/src/store/store.ts:77
sqliteDbWrapper
Section titled “sqliteDbWrapper”sqliteDbWrapper:
SqliteDbWrapper
Defined in: packages/@livestore/livestore/src/store/store.ts:75
storeId
Section titled “storeId”
readonlystoreId:string
Defined in: packages/@livestore/livestore/src/store/store.ts:73
subscribe
Section titled “subscribe”subscribe:
SubscribeFn
Defined in: packages/@livestore/livestore/src/store/store.ts:372
Subscribe to the results of a query.
- When providing an onUpdatecallback it returns an Unsubscribe function.
- Without a callback it returns an AsyncIterable that yields query results.
Examples
Section titled “Examples”const unsubscribe = store.subscribe(query$, (result) => console.log(result))for await (const result of store.subscribe(query$)) {  console.log(result)}syncProcessor
Section titled “syncProcessor”
readonlysyncProcessor:ClientSessionSyncProcessor
Defined in: packages/@livestore/livestore/src/store/store.ts:117
tableRefs
Section titled “tableRefs”tableRefs:
object
Defined in: packages/@livestore/livestore/src/store/store.ts:102
Note we’re using Ref<null> here as we don’t care about the value but only about that something has changed.
This only works in combination with equal: () => false which will always trigger a refresh.
Index Signature
Section titled “Index Signature”[key: string]: Ref<null, ReactivityGraphContext, RefreshReason>
Accessors
Section titled “Accessors”clientId
Section titled “clientId”Get Signature
Section titled “Get Signature”get clientId():
string
Defined in: packages/@livestore/livestore/src/store/store.ts:341
Returns
Section titled “Returns”string
sessionId
Section titled “sessionId”Get Signature
Section titled “Get Signature”get sessionId():
string
Defined in: packages/@livestore/livestore/src/store/store.ts:337
Returns
Section titled “Returns”string
Methods
Section titled “Methods”events()
Section titled “events()”events(
_options?):AsyncIterable<ForSchema<TSchema>>
Defined in: packages/@livestore/livestore/src/store/store.ts:758
Returns an async iterable of events.
Parameters
Section titled “Parameters”_options?
Section titled “_options?”StoreEventsOptions<TSchema>
Returns
Section titled “Returns”AsyncIterable<ForSchema<TSchema>>
Examples
Section titled “Examples”for await (const event of store.events()) {  console.log(event)}// Get all events from the beginning of timefor await (const event of store.events({ cursor: EventSequenceNumber.ROOT })) {  console.log(event)}eventsStream()
Section titled “eventsStream()”eventsStream(
_options?):Stream<ForSchema<TSchema>>
Defined in: packages/@livestore/livestore/src/store/store.ts:764
Parameters
Section titled “Parameters”_options?
Section titled “_options?”StoreEventsOptions<TSchema>
Returns
Section titled “Returns”Stream<ForSchema<TSchema>>
manualRefresh()
Section titled “manualRefresh()”manualRefresh(
options?):void
Defined in: packages/@livestore/livestore/src/store/store.ts:774
This can be used in combination with skipRefresh when committing events.
We might need a better solution for this. Let’s see.
Parameters
Section titled “Parameters”options?
Section titled “options?”label?
Section titled “label?”string
Returns
Section titled “Returns”void
query()
Section titled “query()”query<
TResult>(query,options?):TResult
Defined in: packages/@livestore/livestore/src/store/store.ts:494
Synchronously queries the database without creating a LiveQuery. This is useful for queries that don’t need to be reactive.
Example: Query builder
const completedTodos = store.query(tables.todo.where({ complete: true }))Example: Raw SQL query
const completedTodos = store.query({ query: 'SELECT * FROM todo WHERE complete = 1', bindValues: {} })Type Parameters
Section titled “Type Parameters”TResult
Section titled “TResult”TResult
Parameters
Section titled “Parameters”Queryable<TResult> | { bindValues: Bindable; query: string; schema?: Schema<TResult, TResult, never>; }
options?
Section titled “options?”debugRefreshReason?
Section titled “debugRefreshReason?”otelContext?
Section titled “otelContext?”Context
Returns
Section titled “Returns”TResult
setSignal()
Section titled “setSignal()”setSignal<
T>(signalDef,value):void
Defined in: packages/@livestore/livestore/src/store/store.ts:575
Set the value of a signal
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”signalDef
Section titled “signalDef”SignalDef<T>
T | (prev) => T
Returns
Section titled “Returns”void
Examples
Section titled “Examples”const count$ = signal(0, { label: 'count$' })store.setSignal(count$, 2)const count$ = signal(0, { label: 'count$' })store.setSignal(count$, (prev) => prev + 1)shutdown()
Section titled “shutdown()”shutdown(
cause?):Effect<void>
Defined in: packages/@livestore/livestore/src/store/store.ts:807
Shuts down the store and closes the client session.
This is called automatically when the store was created using the React or Effect API.
Parameters
Section titled “Parameters”cause?
Section titled “cause?”Cause<UnexpectedError | MaterializeError>
Returns
Section titled “Returns”Effect<void>
shutdownPromise()
Section titled “shutdownPromise()”shutdownPromise(
cause?):Promise<void>
Defined in: packages/@livestore/livestore/src/store/store.ts:795
Shuts down the store and closes the client session.
This is called automatically when the store was created using the React or Effect API.
Parameters
Section titled “Parameters”cause?
Section titled “cause?”UnexpectedError
Returns
Section titled “Returns”Promise<void>
subscribeStream()
Section titled “subscribeStream()”subscribeStream<
TResult>(query,options?):Stream<TResult>
Defined in: packages/@livestore/livestore/src/store/store.ts:460
Type Parameters
Section titled “Type Parameters”TResult
Section titled “TResult”TResult
Parameters
Section titled “Parameters”Queryable<TResult>
options?
Section titled “options?”SubscribeOptions<TResult>
Returns
Section titled “Returns”Stream<TResult>
toJSON()
Section titled “toJSON()”toJSON():
object
Defined in: packages/@livestore/livestore/src/store/store.ts:884
Returns
Section titled “Returns”object
_tag:
string='livestore.Store'
reactivityGraph
Section titled “reactivityGraph”reactivityGraph:
ReactiveGraphSnapshot
Overrides
Section titled “Overrides”Inspectable.Class.toJSON
