Open History to see the last commit
1# @tanstack/cloudflare-durable-objects-db-sqlite-persistence
2
3Thin SQLite persistence for Cloudflare Durable Objects.
4
5Start with the [SQLite Persistence guide](../../docs/guides/sqlite-persistence.md) for Collection setup and lifecycle behavior.
6
7## Public API
8
9- `createCloudflareDOSQLitePersistence(...)`
10- `persistedCollectionOptions(...)` (re-exported from core)
11
12## Quick start
13
14```ts
15import { createCollection } from '@tanstack/db'
16import {
17 createCloudflareDOSQLitePersistence,
18 persistedCollectionOptions,
19} from '@tanstack/cloudflare-durable-objects-db-sqlite-persistence'
20
21type Todo = {
22 id: string
23 title: string
24 completed: boolean
25}
26
27export class TodosObject extends DurableObject {
28 persistence = createCloudflareDOSQLitePersistence({
29 // Pass full storage to use native DO transaction support.
30 storage: this.ctx.storage,
31 })
32
33 todos = createCollection(
34 persistedCollectionOptions<Todo, string>({
35 id: `todos`,
36 getKey: (todo) => todo.id,
37 persistence: this.persistence,
38 schemaVersion: 1, // Per-collection schema version
39 }),
40 )
41}
42```
43
44## Notes
45
46- One shared persistence instance can serve multiple collections.
47- Mode defaults are inferred from collection usage:
48 - sync config present => `sync-present-reset`
49 - no sync config => `sync-absent-error`
50- You can still override with `schemaMismatchPolicy` if needed.