Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions packages/db-expo-sqlite-persisted-collection/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# @tanstack/db-expo-sqlite-persisted-collection

Thin SQLite persistence for Expo apps using the official `expo-sqlite` adapter.

## Public API

- `createExpoSQLitePersistence(...)`
- `persistedCollectionOptions(...)` (re-exported from core)

## Quick start

```ts
import * as SQLite from 'expo-sqlite'
import { createCollection } from '@tanstack/db'
import {
createExpoSQLitePersistence,
persistedCollectionOptions,
} from '@tanstack/db-expo-sqlite-persisted-collection'

type Todo = {
id: string
title: string
completed: boolean
}

const database = await SQLite.openDatabaseAsync(`tanstack-db.sqlite`)

// One shared persistence instance for the whole database.
const persistence = createExpoSQLitePersistence({
database,
})

export const todosCollection = createCollection(
persistedCollectionOptions<Todo, string>({
id: `todos`,
getKey: (todo) => todo.id,
persistence,
schemaVersion: 1, // Per-collection schema version
}),
)
```

## Notes

- This package targets the official `expo-sqlite` async database API.
- `createExpoSQLitePersistence` is shared across collections.
- Mode defaults (`sync-present` vs `sync-absent`) are inferred from whether a
`sync` config is present in `persistedCollectionOptions`.
- The React Native `op-sqlite` wrapper remains available in
`@tanstack/db-react-native-sqlite-persisted-collection`.
- Expo web is not part of the emulator-backed E2E path in this package. Use the
browser SQLite package for browser-focused persistence coverage.

## E2E

- `pnpm --filter @tanstack/db-expo-sqlite-persisted-collection test:e2e`
runs the shared Node-backed conformance suite.
- `pnpm --filter @tanstack/db-expo-sqlite-persisted-collection test:e2e:expo:ios`
runs the real Expo iOS Simulator path.
- `pnpm --filter @tanstack/db-expo-sqlite-persisted-collection test:e2e:expo:android`
runs the real Expo Android Emulator path.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { expect, it } from 'vitest'
import { ensureExpoEmulatorRuntime } from '../tests/helpers/expo-emulator-runtime'

const runtimePlatform = process.env.TANSTACK_DB_EXPO_RUNTIME_PLATFORM?.trim()
const shouldRun = runtimePlatform === `ios` || runtimePlatform === `android`

it.runIf(shouldRun)(
`runs a persistence smoke test inside a real Expo runtime`,
async () => {
const runtime = await ensureExpoEmulatorRuntime(
runtimePlatform === `android` ? `android` : `ios`,
)
const smokeResult = await runtime.runPersistenceSmokeTest(
`expo-runtime-smoke.sqlite`,
)

expect(smokeResult.insertedTitle).toBe(`Persisted from Expo runtime`)
expect(smokeResult.reloadedCount).toBe(1)
},
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { it } from 'vitest'
import { createExpoSQLitePersistence } from '../src'
import { runMobilePersistedCollectionConformanceSuite } from './mobile-persisted-collection-conformance-suite'

const runtimePlatform = process.env.TANSTACK_DB_EXPO_RUNTIME_PLATFORM?.trim()

if (!runtimePlatform) {
runMobilePersistedCollectionConformanceSuite(
`expo persisted collection conformance`,
(database) => createExpoSQLitePersistence({ database }),
)
} else {
it.skip(`runs the conformance suite in shimmed e2e mode only`, () => {})
}
Loading
Loading