@tanstack/node-db-sqlite-persistence
v0.1.5
Published
Node SQLite persisted collection adapter for TanStack DB
Downloads
309
Readme
@tanstack/node-db-sqlite-persistence
Thin Node SQLite persistence for TanStack DB.
Public API
createNodeSQLitePersistence(...)persistedCollectionOptions(...)(re-exported from core)
Quick start
import { createCollection } from '@tanstack/db'
import {
createNodeSQLitePersistence,
persistedCollectionOptions,
} from '@tanstack/node-db-sqlite-persistence'
import Database from 'better-sqlite3'
type Todo = {
id: string
title: string
completed: boolean
}
// You own database lifecycle directly.
const database = new Database(`./tanstack-db.sqlite`)
// One shared persistence instance for the whole database.
const persistence = createNodeSQLitePersistence({
database,
})
export const todosCollection = createCollection(
persistedCollectionOptions<Todo, string>({
id: `todos`,
getKey: (todo) => todo.id,
persistence,
schemaVersion: 1, // Per-collection schema version
}),
)Notes
createNodeSQLitePersistenceis shared across collections; it resolves mode-specific behavior (sync-presentvssync-absent) automatically.schemaVersionis specified per collection viapersistedCollectionOptions.- Call
database.close()when your app shuts down.
