Store is the central interface to a LiveStore database. It provides reactive queries, event commits, and sync. You can create a store imperatively with createStorePromise, inside an Effect with createStore, or through a StoreRegistry for managed lifecycle in framework applications.
createStorePromise
Creates a Store and returns a Promise that resolves once the store has booted.
CreateStoreOptionsPromise
Extends CreateStoreOptions with two additional fields:
An
AbortSignal that, when aborted, shuts down the store by closing its lifetime scope.OpenTelemetry configuration for the root span context used during store boot.
createStore
The Effect-based variant. Returns an Effect that yields a Store, scoped to the provided Scope. Prefer this when composing stores inside Effect services or layers.
CreateStoreOptions
All fields accepted by createStore (and therefore by createStorePromise).
The LiveStore schema defining tables, events, and materializers. Build this with
makeSchema().The adapter used for storage and synchronization (e.g.,
@livestore/adapter-web, @livestore/adapter-node).Stable identifier for this store instance. Used for persistence and multi-tenancy isolation.
- Only alphanumeric characters, underscores (
_), and hyphens (-) are allowed. Must match/^[a-zA-Z0-9_-]+$/. - Use a globally unique ID to prevent collisions (e.g.,
nanoid()). - Prefix with a namespace to make debugging easier (e.g.,
app-root,workspace-abc123).
User-defined context attached to the store. Useful for dependency injection—accessible at
store.context.Optional async callback invoked after the store has initialized but before
createStorePromise resolves. Use it to seed initial data or run startup migrations.Wraps reactive notifications in a batching function to avoid redundant re-renders. In React applications pass
unstable_batchedUpdates from react-dom or react-native.Controls whether the LiveStore DevTools extension is connected.
'auto' enables DevTools in development environments only.Callback invoked at each stage of the boot sequence. Useful for displaying progress indicators.
Effect Schema describing the payload sent to the sync backend when connecting. Defaults to
Schema.JsonValue (untyped). Provide a typed schema for end-to-end type safety.The payload sent to the sync backend. Its type is inferred from
syncPayloadSchema.When
true, registers a beforeunload listener to warn users about unsaved changes. Web adapter only.An Effect
Deferred that is completed when the store shuts down. Use makeShutdownDeferred() to create one and await it to block until shutdown completes.Advanced tuning options.
Store instance methods
Once you have a Store, use these methods to interact with it.
store.query(queryable)
Synchronously reads the current value of a query, signal, or computed without creating a reactive subscription.
store.subscribe(queryable, onUpdate, options?)
Subscribes to a reactive query. Calls onUpdate immediately with the current value and again whenever the result changes.
Returns an Unsubscribe function when onUpdate is provided. When called without a callback it returns an AsyncIterable<TResult>.
Human-readable label shown in DevTools for this subscription.
When
true, skips calling onUpdate for the initial value. The subscription still registers its reactive dependencies.Callback invoked when the subscription is established, receiving the live query instance.
Callback invoked when the subscription is terminated.
store.commit(...events)
Commits one or more events to the store. Events are immediately materialized into the local SQLite database and asynchronously synced to other clients.
store.events(options?)
Returns an AsyncIterable of events from the eventlog. Only events confirmed by the sync backend are included.
Only emit events of the given names. Defaults to all event types.
Start streaming from this event sequence number.
Stop the stream once this event is reached.
Maximum events fetched per database query. Maximum allowed value is 1000.
store.shutdown()
Shuts down the store and closes the client session. Returns an Effect.
store.shutdownPromise()
Promise-based shutdown. Awaits complete cleanup.
store.syncStatus()
Returns the current sync state between the local session and the leader thread.
store.subscribeSyncStatus(onUpdate)
Subscribes to sync status changes. Invokes onUpdate immediately and on every state change.
store.setSignal(signalDef, value)
Sets the value of a signal. Accepts a new value or a function that receives the previous value.
StoreRegistry
StoreRegistry manages store lifecycle for framework integrations. It caches stores by storeId, reference-counts them, and disposes them after unusedCacheTime milliseconds when they have no active consumers.
registry.getOrLoadPromise(options)
Returns the store synchronously if already cached, or a Promise if it is loading. Concurrent calls with the same storeId receive the same Promise reference.
registry.getOrLoad(options)
Effect-based variant. Yields the store scoped to the caller’s Scope.
registry.retain(options)
Keeps the store alive regardless of component lifecycle. Returns a release function.
registry.preload(options)
Fire-and-forget store preloading to warm the cache before it is needed.
registry.dispose()
Disposes the registry and all managed stores, releasing database connections, WebSocket connections, and web workers.
storeOptions
A helper that returns its argument unchanged while enabling TypeScript’s excess property checking. Use it to define reusable store configurations that can be shared across useStore(), preload(), and getOrLoad().
Effect integration: makeStoreContext
For Effect-based applications, create a typed store context that preserves your schema types:
StoreContext exposes:
Context tag for dependency injection. Yield it in Effect code to access
{ store }.Creates a layer that boots the store and provides it to the context.
Tag for async initialization patterns where the store is provided later.
makeStoreContext() is the recommended way to use LiveStore with Effect. It preserves full schema types, unlike the deprecated LiveStoreContextRunning service.