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

README.md

51 lines1.2 KB

1# @tanstack/react-native-db-sqlite-persistence
2​
3Thin SQLite persistence for React Native apps (including Expo runtime).
4​
5## Public API
6​
7- `createReactNativeSQLitePersistence(...)`
8- `persistedCollectionOptions(...)` (re-exported from core)
9​
10## Quick start
11​
12```ts
13import { open } from '@op-engineering/op-sqlite'
14import { createCollection } from '@tanstack/db'
15import {
16 createReactNativeSQLitePersistence,
17 persistedCollectionOptions,
18} from '@tanstack/react-native-db-sqlite-persistence'
19​
20type Todo = {
21 id: string
22 title: string
23 completed: boolean
25​
26const database = open({
27 name: `tanstack-db.sqlite`,
28 location: `default`,
29})
30​
31// One shared persistence instance for the whole database.
32const persistence = createReactNativeSQLitePersistence({
33 database,
34})
35​
36export const todosCollection = createCollection(
37 persistedCollectionOptions<Todo, string>({
38 id: `todos`,
39 getKey: (todo) => todo.id,
40 persistence,
41 schemaVersion: 1, // Per-collection schema version
42 }),
44```
45​
46## Notes
47​
48- The same API is used for React Native and Expo runtimes.
49- `createReactNativeSQLitePersistence` is shared across collections.
50- Mode defaults (`sync-present` vs `sync-absent`) are inferred from whether a
51 `sync` config is present in `persistedCollectionOptions`.