@tanstack/tauri-db-sqlite-persistence
v0.1.5
Published
Tauri SQLite persisted collection adapter for TanStack DB
Downloads
301
Readme
@tanstack/tauri-db-sqlite-persistence
Thin SQLite persistence for Tauri apps using @tauri-apps/plugin-sql.
Public API
createTauriSQLitePersistence(...)persistedCollectionOptions(...)(re-exported from core)
Install
pnpm add @tanstack/tauri-db-sqlite-persistence @tauri-apps/plugin-sqlConsumer-side Tauri setup
Install the official SQL plugin in your Tauri app:
cd src-tauri
cargo add tauri-plugin-sql --features sqliteRegister the plugin in src-tauri/src/main.rs:
fn main() {
tauri::Builder::default()
.plugin(tauri_plugin_sql::Builder::default().build())
.run(tauri::generate_context!())
.expect("error while running tauri application");
}Enable the SQL permissions in src-tauri/capabilities/default.json:
{
"permissions": ["core:default", "sql:default", "sql:allow-execute"]
}Quick start
import Database from '@tauri-apps/plugin-sql'
import { createCollection } from '@tanstack/db'
import {
createTauriSQLitePersistence,
persistedCollectionOptions,
} from '@tanstack/tauri-db-sqlite-persistence'
type Todo = {
id: string
title: string
completed: boolean
}
const database = await Database.load(`sqlite:tanstack-db.sqlite`)
const persistence = createTauriSQLitePersistence({
database,
})
export const todosCollection = createCollection(
persistedCollectionOptions<Todo, string>({
id: `todos`,
getKey: (todo) => todo.id,
persistence,
schemaVersion: 1,
}),
)Notes
createTauriSQLitePersistenceis shared across collections.- Reuse a single
Database.load('sqlite:...')handle per SQLite file when using this package. Opening multiple plugin handles to the same file can reintroduce SQLite locking behavior outside this package's serialized transaction queue. - Mode defaults (
sync-presentvssync-absent) are inferred from whether asyncconfig is present inpersistedCollectionOptions. - This package expects a database handle created by
@tauri-apps/plugin-sql, typically fromDatabase.load('sqlite:...'). - The database path is resolved by Tauri's SQL plugin, not by this package.
- This package does not publish or require package-specific Rust code. Only the app-level Tauri SQL plugin registration shown above is required.
Testing
pnpm --filter @tanstack/tauri-db-sqlite-persistence testruns the driver and shared adapter contract tests.pnpm --filter @tanstack/tauri-db-sqlite-persistence test:e2ebuilds the repo-local Tauri harness and runs the persisted collection conformance suite inside a real Tauri runtime.
