NodeSqliteWrapper

See source code
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_metadata

Constructor

Constructs a new instance of the NodeSqliteWrapper class

Parameters

NameDescription

db

config

TLSyncSqliteWrapperConfig | undefined;

Properties

config

optional
config?: TLSyncSqliteWrapperConfig | undefined;

Methods

exec( )

exec(sql: string): void;

Parameters

NameDescription

sql

string;

Returns

void;

prepare( )

prepare<
  TResult extends TLSqliteRow | void = void,
  TParams extends TLSqliteInputValue[] = TLSqliteInputValue[],
>(sql: string): TLSyncSqliteStatement<TResult, TParams>;

Parameters

NameDescription

sql

string;

Returns

TLSyncSqliteStatement<TResult, TParams>;

transaction( )

transaction<T>(callback: () => T): T;

Parameters

NameDescription

callback

() => T;

Returns

T;

Prev
JsonChunkAssembler
Next
SQLiteSyncStorage