/** * SQLite driver on node:sqlite, which both Node and Bun provide. * Exposes the small statement/transaction surface RESPLite uses and returns BLOB * columns as Buffer (node:sqlite returns Uint8Array). */ import type { DatabaseSyncOptions, SQLInputValue, StatementResultingChanges, StatementSync } from 'node:sqlite'; /** Column value as read back: BLOBs become Buffers, INTEGERs are BigInt with safeIntegers(). */ export type SqlValue = null | number | bigint | string | Buffer; /** * A row keyed by column name. Columns are typed `any` because each query * defines its own shape; storage modules narrow them at the call site. */ export type Row = Record; export type { SQLInputValue }; /** * Statements always read rows as arrays: building plain objects from column * names is faster than copying node:sqlite's null-prototype row objects. */ export declare class Statement { #private; constructor(stmt: StatementSync); /** Return only the first column of each row. */ pluck(toggle?: boolean): this; /** Return rows as arrays of column values. */ raw(toggle?: boolean): this; /** Read INTEGER columns as BigInt. */ safeIntegers(toggle?: boolean): this; run(...params: SQLInputValue[]): StatementResultingChanges; /** Row object, value array (raw) or first column (pluck); undefined when no row matches. */ get(...params: SQLInputValue[]): any; /** Rows one at a time; breaking out of the loop resets the statement. */ iterate(...params: SQLInputValue[]): Generator; all(...params: SQLInputValue[]): any[]; } type AnyFunction = (...args: any[]) => any; export default class Database { #private; readonly name: string; /** * @param filename - Database file path or ':memory:' */ constructor(filename: string, options?: DatabaseSyncOptions); prepare(sql: string): Statement; exec(sql: string): this; get inTransaction(): boolean; /** * Register undo for in-memory state that mirrors a write just made. It runs if the * enclosing transaction or savepoint rolls back; outside a transaction the write is * already committed and nothing is registered. */ onRollback(undo: () => void): void; /** * Wrap fn so each call runs in a transaction; nested calls use savepoints. * The `.immediate` variant takes the write lock at BEGIN. */ transaction(fn: F): F & { immediate: F; }; close(): void; }