DurableObjectSqliteSyncWrapper
See source codeTable 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 {
DurableObjectSqliteSyncWrapper,
SQLiteSyncStorage,
} 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 | undefinedMethods
exec( )
exec(sql: string): voidParameters
| Name | Description |
|---|---|
| |
Returns
voidprepare( )
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): TParameters
| Name | Description |
|---|---|
| |
Returns
TPrev
StoreSideEffectsNext
InMemorySyncStorage