DurableObjectSqliteSyncWrapper
Table of contents
A wrapper around Cloudflare Durable Object's SqlStorage that implements TLSyncSqliteWrapper.
Use this wrapper with SQLiteSyncStorage to persist tldraw sync state using Cloudflare Durable Object's built-in SQLite storage. This provides automatic persistence that survives Durable Object hibernation and restarts.
class DurableObjectSqliteSyncWrapper implements TLSyncSqliteWrapper {}Example
import {
SQLiteSyncStorage,
DurableObjectSqliteSyncWrapper,
} from "@tldraw/sync-core";
// In your Durable Object class:
class MyDurableObject extends DurableObject {
private storage: SQLiteSyncStorage;
constructor(ctx: DurableObjectState, env: Env) {
super(ctx, env);
const sql = new DurableObjectSqliteSyncWrapper(ctx.storage);
this.storage = new SQLiteSyncStorage({ sql });
}
}// With table prefix to avoid conflicts with other tables
const sql = new DurableObjectSqliteSyncWrapper(this.ctx.storage, {
tablePrefix: "tldraw_",
});
// Creates tables: tldraw_documents, tldraw_tombstones, tldraw_metadataConstructor
Constructs a new instance of the DurableObjectSqliteSyncWrapper 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[] = [],
>(sql: string): TLSyncSqliteStatement<TResult, TParams>;Parameters
| Name | Description |
|---|---|
| |
Returns
TLSyncSqliteStatement<TResult, TParams>;transaction( )
transaction<T>(callback: () => T): T;Parameters
| Name | Description |
|---|---|
| |
Returns
T;Prev
StoreSideEffectsNext
InMemorySyncStorage