Open History to see the last commit
1# @tanstack/browser-db-sqlite-persistence
2
3Thin browser SQLite persistence for TanStack DB using `wa-sqlite` + OPFS.
4
5## Public API
6
7- `createBrowserWASQLitePersistence(...)`
8- `openBrowserWASQLiteOPFSDatabase(...)`
9- `persistedCollectionOptions(...)` (re-exported from core)
10
11## Quick start
12
13```ts
14import { createCollection } from '@tanstack/db'
15import {
16 createBrowserWASQLitePersistence,
17 openBrowserWASQLiteOPFSDatabase,
18 persistedCollectionOptions,
19} from '@tanstack/browser-db-sqlite-persistence'
20
21type Todo = {
22 id: string
23 title: string
24 completed: boolean
25}
26
27const database = await openBrowserWASQLiteOPFSDatabase({
28 databaseName: `tanstack-db.sqlite`,
29})
30
31const persistence = createBrowserWASQLitePersistence({
32 database,
33})
34
35export const todosCollection = createCollection(
36 persistedCollectionOptions<Todo, string>({
37 id: `todos`,
38 getKey: (todo) => todo.id,
39 persistence,
40 schemaVersion: 1, // Per-collection schema version
41 }),
42)
43```
44
45## Notes
46
47- This package is Phase 7 single-tab browser wiring: it uses
48 `SingleProcessCoordinator` semantics by default.
49- `openBrowserWASQLiteOPFSDatabase(...)` starts a dedicated Web Worker and
50 routes SQL operations through it. OPFS sync access handle APIs are used in
51 that worker context.
52- Single-tab mode does not require BroadcastChannel or Web Locks for
53 correctness.
54- OPFS capability failures are surfaced as `PersistenceUnavailableError`.