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

README.md

66 lines2.1 KB

1# @tanstack/expo-db-sqlite-persistence
2​
3Thin SQLite persistence for Expo apps using the official `expo-sqlite` adapter.
4​
5Start with the [SQLite Persistence guide](../../docs/guides/sqlite-persistence.md) for Collection setup and lifecycle behavior.
6​
7## Public API
8​
9- `createExpoSQLitePersistence(...)`
10- `persistedCollectionOptions(...)` (re-exported from core)
11- Advanced driver entrypoint:
12 `@tanstack/expo-db-sqlite-persistence/expo-sqlite-driver`
13​
14## Quick start
15​
16```ts
17import * as SQLite from 'expo-sqlite'
18import { createCollection } from '@tanstack/db'
19import {
20 createExpoSQLitePersistence,
21 persistedCollectionOptions,
22} from '@tanstack/expo-db-sqlite-persistence'
23​
24type Todo = {
25 id: string
26 title: string
27 completed: boolean
29​
30const database = await SQLite.openDatabaseAsync(`tanstack-db.sqlite`)
31​
32// One shared persistence instance for the whole database.
33const persistence = createExpoSQLitePersistence({
34 database,
35})
36​
37export const todosCollection = createCollection(
38 persistedCollectionOptions<Todo, string>({
39 id: `todos`,
40 getKey: (todo) => todo.id,
41 persistence,
42 schemaVersion: 1, // Per-collection schema version
43 }),
45```
46​
47## Notes
48​
49- This package targets the official `expo-sqlite` async database API.
50- Requires `expo-sqlite` `^55.0.10` or `^57.0.0` (documented as a peer dependency).
51- `createExpoSQLitePersistence` is shared across collections.
52- Mode defaults (`sync-present` vs `sync-absent`) are inferred from whether a
53 `sync` config is present in `persistedCollectionOptions`.
54- The React Native `op-sqlite` wrapper remains available in
55 `@tanstack/react-native-db-sqlite-persistence`.
56- Expo web is not part of the emulator-backed E2E path in this package. Use the
57 browser SQLite package for browser-focused persistence coverage.
58​
59## E2E
60​
61- `pnpm --filter @tanstack/expo-db-sqlite-persistence test:e2e`
62 runs the shared Node-backed conformance suite.
63- `pnpm --filter @tanstack/expo-db-sqlite-persistence test:e2e:expo:ios`
64 runs the real Expo iOS Simulator path.
65- `pnpm --filter @tanstack/expo-db-sqlite-persistence test:e2e:expo:android`
66 runs the real Expo Android Emulator path.