NodeSqliteWrapper
Table 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 { DatabaseSync } from "node:sqlite";
import { SQLiteSyncStorage, NodeSqliteWrapper } from "@tldraw/sync-core";
const db = new DatabaseSync(":memory:");
const sql = new NodeSqliteWrapper(db);
const storage = new SQLiteSyncStorage({ sql });// With better-sqlite3
import Database from "better-sqlite3";
import { SQLiteSyncStorage, NodeSqliteWrapper } from "@tldraw/sync-core";
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 | undefined;Methods
exec( )
exec(sql: string): void;Parameters
| Name | Description |
|---|---|
| |
Returns
void;prepare( )
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): T;Parameters
| Name | Description |
|---|---|
| |
Returns
T;Prev
JsonChunkAssemblerNext
SQLiteSyncStorage