@tanstack/react-native-db-sqlite-persistence
v0.1.5
Published
React Native and Expo SQLite persisted collection adapter for TanStack DB
Readme
@tanstack/react-native-db-sqlite-persistence
Thin SQLite persistence for React Native apps (including Expo runtime).
Public API
createReactNativeSQLitePersistence(...)persistedCollectionOptions(...)(re-exported from core)
Quick start
import { open } from '@op-engineering/op-sqlite'
import { createCollection } from '@tanstack/db'
import {
createReactNativeSQLitePersistence,
persistedCollectionOptions,
} from '@tanstack/react-native-db-sqlite-persistence'
type Todo = {
id: string
title: string
completed: boolean
}
const database = open({
name: `tanstack-db.sqlite`,
location: `default`,
})
// One shared persistence instance for the whole database.
const persistence = createReactNativeSQLitePersistence({
database,
})
export const todosCollection = createCollection(
persistedCollectionOptions<Todo, string>({
id: `todos`,
getKey: (todo) => todo.id,
persistence,
schemaVersion: 1, // Per-collection schema version
}),
)Notes
- The same API is used for React Native and Expo runtimes.
createReactNativeSQLitePersistenceis shared across collections.- Mode defaults (
sync-presentvssync-absent) are inferred from whether asyncconfig is present inpersistedCollectionOptions.
