import { Database as BunDatabase, type SQLQueryBindings } from "bun:sqlite"; import { type AcquireWriteLockOptions, type ProcessRole } from "./advisory-lock"; /** Param array accepted by query helpers */ type Params = SQLQueryBindings[]; export interface DatabaseOptions { processRole?: ProcessRole; } export type WalCheckpointMode = "PASSIVE" | "FULL" | "RESTART" | "TRUNCATE"; export interface WalCheckpointResult { mode: WalCheckpointMode; busy: number; logFrames: number; checkpointedFrames: number; } export interface IntegrityCheckResult { ok: boolean; messages: string[]; maxErrors: number; } /** A database migration with version, name, and SQL to apply. */ export interface Migration { version: number; name: string; up: string; } /** * Manages the SQLite connection lifecycle: opening, configuring (WAL mode, * foreign keys, busy timeout), running migrations, and exposing typed * query helpers. Wraps bun:sqlite. */ export declare class Database { private db; private dbPath; private advisoryWriteLockPath; private processRole; private transactionDepth; private _hasVectorExtension; static enableExtensionSupport(): boolean; constructor(dbPath: string, options?: DatabaseOptions); private open; private configure; private runConfigureStage; private throwConfigureFailure; private applyPragmas; private loadExtensions; get hasVectorExtension(): boolean; private ensureMigrationTable; /** * Run pending migrations in version order. Already-applied migrations * are skipped. Each migration runs inside a transaction. */ migrate(migrations: Migration[]): void; /** * Retry a synchronous database operation with exponential backoff. * Transient errors (SQLITE_BUSY, SQLITE_IOERR_VNODE, etc.) are retried * up to MAX_RETRIES times; all other errors propagate immediately. */ private withRetry; /** Execute a write statement (INSERT / UPDATE / DELETE) with optional params */ run(sql: string, params?: Params): void; /** Fetch a single row, or null if not found */ get(sql: string, params?: Params): T | null; /** Fetch all matching rows */ all(sql: string, params?: Params): T[]; /** Execute raw SQL (multiple statements, no params) */ exec(sql: string): void; /** Wrap a function in a SQLite transaction — auto-commits or rolls back */ transaction(fn: () => T): T; /** Advisory write lock path associated with this database path. */ get writeLockPath(): string; /** * Execute a callback under the cross-process advisory write lock. */ withAdvisoryWriteLock(role: ProcessRole, fn: () => T, options?: Omit): T; checkpointWal(mode?: WalCheckpointMode): WalCheckpointResult; integrityCheck(maxErrors?: number): IntegrityCheckResult; /** Close the database connection */ close(): void; /** Check whether the connection is still usable */ get isOpen(): boolean; /** Access the underlying bun:sqlite instance for advanced use */ get raw(): BunDatabase; } /** Create and configure a Database instance at the given path */ export declare function createDatabase(dbPath: string, options?: DatabaseOptions): Database; export {}; //# sourceMappingURL=database.d.ts.map