NodeSqliteWrapper
See source codeTable of contents
A wrapper around synchronous SQLite databases that implements TLSyncSqliteWrapper. Works with both node:sqlite DatabaseSync (Node.js 22.5+) and better-sqlite3 Database.
Use this wrapper with SQLiteSyncStorage to persist tldraw sync state to a SQLite database in Node.js environments.
class NodeSqliteWrapper implements TLSyncSqliteWrapper {}Example
// With node:sqlite (Node.js 22.5+)
import { NodeSqliteWrapper, SQLiteSyncStorage } from '@tldraw/sync-core'
import { DatabaseSync } from 'node:sqlite'
const db = new DatabaseSync(':memory:')
const sql = new NodeSqliteWrapper(db)
const storage = new SQLiteSyncStorage({ sql })// With better-sqlite3
import { NodeSqliteWrapper, SQLiteSyncStorage } from '@tldraw/sync-core'
import Database from 'better-sqlite3'
const db = new Database(':memory:')
const sql = new NodeSqliteWrapper(db)
const storage = new SQLiteSyncStorage({ sql })// With table prefix to avoid conflicts with other tables
const sql = new NodeSqliteWrapper(db, { tablePrefix: 'tldraw_' })
// Creates tables: tldraw_documents, tldraw_tombstones, tldraw_metadataConstructor
Constructs a new instance of the NodeSqliteWrapper class
Parameters
| Name | Description |
|---|---|
| |
| |
Properties
config
optional
config?: TLSyncSqliteWrapperConfig | undefinedMethods
exec( )
exec(sql: string): voidParameters
| Name | Description |
|---|---|
| |
Returns
voidprepare( )
prepare<
TResult extends TLSqliteRow | void = void,
TParams extends TLSqliteInputValue[] = TLSqliteInputValue[],
>(sql: string): TLSyncSqliteStatement<TResult, TParams>Parameters
| Name | Description |
|---|---|
| |
Returns
TLSyncSqliteStatement<TResult, TParams>transaction( )
transaction<T>(callback: () => T): TParameters
| Name | Description |
|---|---|
| |
Returns
TPrev
JsonChunkAssemblerNext
SQLiteSyncStorage