Skip to content
Source
Sign inSign up
TanStack/db
Open History to see the last commit

README.md

49 lines1.2 KB

1# @tanstack/node-db-sqlite-persistence
2​
3Thin Node SQLite persistence for TanStack DB.
4​
5## Public API
6​
7- `createNodeSQLitePersistence(...)`
8- `persistedCollectionOptions(...)` (re-exported from core)
9​
10## Quick start
11​
12```ts
13import { createCollection } from '@tanstack/db'
14import {
15 createNodeSQLitePersistence,
16 persistedCollectionOptions,
17} from '@tanstack/node-db-sqlite-persistence'
18import Database from 'better-sqlite3'
19​
20type Todo = {
21 id: string
22 title: string
23 completed: boolean
25​
26// You own database lifecycle directly.
27const database = new Database(`./tanstack-db.sqlite`)
28​
29// One shared persistence instance for the whole database.
30const persistence = createNodeSQLitePersistence({
31 database,
32})
33​
34export const todosCollection = createCollection(
35 persistedCollectionOptions<Todo, string>({
36 id: `todos`,
37 getKey: (todo) => todo.id,
38 persistence,
39 schemaVersion: 1, // Per-collection schema version
40 }),
42```
43​
44## Notes
45​
46- `createNodeSQLitePersistence` is shared across collections; it resolves
47 mode-specific behavior (`sync-present` vs `sync-absent`) automatically.
48- `schemaVersion` is specified per collection via `persistedCollectionOptions`.
49- Call `database.close()` when your app shuts down.