SQLiteSyncStorage
See source codeTable of contents
SQLite-based implementation of TLSyncStorage. Stores documents, tombstones, metadata, and clock values in SQLite tables.
This storage backend provides persistent synchronization state that survives process restarts, unlike InMemorySyncStorage which loses data when the process ends.
class SQLiteSyncStorage<R extends UnknownRecord> implements TLSyncStorage<R> {}Example
// With Cloudflare Durable Objects
import {
DurableObjectSqliteSyncWrapper,
SQLiteSyncStorage,
} from '@tldraw/sync-core'
const sql = new DurableObjectSqliteSyncWrapper(this.ctx.storage)
const storage = new SQLiteSyncStorage({ sql })// With Node.js sqlite (Node 22.5+)
import { NodeSqliteWrapper, SQLiteSyncStorage } from '@tldraw/sync-core'
import { DatabaseSync } from 'node:sqlite'
const db = new DatabaseSync('sync-state.db')
const sql = new NodeSqliteWrapper(db)
const storage = new SQLiteSyncStorage({ sql })// Initialize with an existing snapshot
const storage = new SQLiteSyncStorage({ sql, snapshot: existingSnapshot })Constructor
Constructs a new instance of the SQLiteSyncStorage class
Parameters
| Name | Description |
|---|---|
| |
Methods
getDocumentClock( )
static
Get the current document clock value from storage without fully initializing. Returns null if storage has not been initialized. Useful for comparing storage freshness against external sources.
static getDocumentClock(storage: TLSyncSqliteWrapper): null | numberParameters
| Name | Description |
|---|---|
|
Returns
null | numberhasBeenInitialized( )
static
Check if the storage has been initialized (has data in the clock table). Useful for determining whether to load from an external source on first access.
static hasBeenInitialized(storage: TLSyncSqliteWrapper): booleanParameters
| Name | Description |
|---|---|
|
Returns
booleangetClock( )
getClock(): numbergetSnapshot( )
getSnapshot(): RoomSnapshotonChange( )
onChange(
callback: (arg: TLSyncStorageOnChangeCallbackProps) => void
): () => voidParameters
| Name | Description |
|---|---|
| |
Returns
() => voidtransaction( )
transaction<T>(
callback: TLSyncStorageTransactionCallback<R, T>,
opts?: TLSyncStorageTransactionOptions
): TLSyncStorageTransactionResult<T, R>Parameters
| Name | Description |
|---|---|
| |
|
Returns
Prev
NodeSqliteWrapperNext
TLRemoteSyncError