zidane/ session/ sqlite
A SQLite-backed session store for Bun.
import { … } from 'zidane/session/sqlite'src/session/sqlite.ts
Use createSqliteStore when sessions must survive a restart. It writes each turn as it completes, in SQLite's write-ahead-log (WAL) mode, so a crash keeps history up to the last finished turn. It needs Bun (bun:sqlite), so it has its own subpath. See Sessions.
import { createSession } from 'zidane/session'
import { createSqliteStore } from 'zidane/session/sqlite'
const store = createSqliteStore({ path: './sessions.db' })
const session = await createSession({ store })
await session.save()
console.log(session.id)Functions#
createSqliteStoreFunction#
Creates a SessionStore backed by a SQLite file through bun:sqlite. Corruption errors are rethrown with the file path and a recovery recipe.
function createSqliteStore(options: SqliteStoreOptions): SessionStoreParameters
| Name | Type | Description |
|---|---|---|
| options | SqliteStoreOptions | Database path. |
Returns
Example
import { createSession } from 'zidane/session'
import { createSqliteStore } from 'zidane/session/sqlite'
const store = createSqliteStore({ path: './sessions.db' })
const session = await createSession({ store })createTuiStoreFunction#
Convenience: open a SQLite store at dbPath, creating its parent
directory if it doesn't yet exist. Meant as the store factory of
resolveConfig, for example store: paths => createTuiStore(paths.db).
Lives here (and not in zidane/chat) so the renderer-agnostic
zidane/chat entry stays free of bun:sqlite — non-Bun consumers
can import zidane/chat without pulling in the Bun-only binding.
function createTuiStore(dbPath: string): SessionStoreParameters
| Name | Type | Description |
|---|---|---|
| dbPath | string | Path of the SQLite database file. The parent directory is created when missing. |
Returns
describeCorruptDbFunction#
Re-wrap a corruption error with the file path and a recovery recipe. The bare SQLite string ("database disk image is malformed") tells the user nothing about WHICH file or what to do; every host (TUI, daemon, headless) surfaces this message instead. Non-corruption errors pass through untouched.
Deliberately no auto-repair / quarantine: the file is the only copy of
the user's history and .recover salvages most of it. Never touch it.
function describeCorruptDb(err: unknown, dbPath: string): unknownParameters
| Name | Type | Description |
|---|---|---|
| err | unknown | Error thrown by a SQLite operation. |
| dbPath | string | Path of the database file, named in the message. |
Returns
unknownisCorruptDbErrorFunction#
True when err is SQLite reporting a damaged file (SQLITE_CORRUPT,
SQLITE_NOTADB). Matched on the message because bun:sqlite's error
class exposes the code inconsistently across versions.
function isCorruptDbError(err: unknown): booleanParameters
| Name | Type | Description |
|---|---|---|
| err | unknown | Error thrown by a SQLite operation. |
Returns
booleanInterfaces#
SqliteStoreOptionsInterface#
Options for createSqliteStore.
interface SqliteStoreOptionsProperties
| Name | Type | Description |
|---|---|---|
| path | string | Path to the SQLite database file |