/** * SQLite connection manager for @npm-safe/core. * * Owns a single `better-sqlite3` connection, configures WAL-mode pragmas for * safe concurrent reads, and runs the migration list declared in * {@link ./schema.ts} on construction. This module is pure connection + * migration management — no query helpers, no caching, no business logic. * * @module store/database */ import Database from "better-sqlite3"; /** * Error thrown by {@link DatabaseManager} when the underlying `better-sqlite3` * operation fails (open, pragma, migration). Wraps the original error so * callers can branch on a single typed error while still inspecting the cause. */ export declare class DatabaseManagerError extends Error { readonly cause?: unknown | undefined; /** * @param message - Human-readable error message. * @param cause - The underlying error, if any. */ constructor(message: string, cause?: unknown | undefined); } /** * Manages the lifecycle of a single SQLite database connection. * * On construction it opens the database file (creating it if missing), * applies WAL-mode and safety pragmas, then runs any unapplied migrations * from {@link getMigrationList} inside a transaction. The connection is * kept open and accessible via {@link DatabaseManager.getDb} until * {@link DatabaseManager.close} is called. */ export declare class DatabaseManager { /** Underlying better-sqlite3 connection, or `null` after `close()`. */ private db; /** * Opens (or creates) the database at `dbPath`, configures pragmas, and * runs pending migrations. Throws {@link DatabaseManagerError} on any * failure during open, pragma, or migration. * * @param dbPath - Filesystem path to the SQLite database file. */ constructor(dbPath: string); /** * Apply the connection-level pragmas: WAL journal mode, a 5s busy timeout, * NORMAL synchronous (safe under WAL), and foreign-key enforcement. */ private applyPragmas; /** * Run all migrations from {@link getMigrationList} that have not yet been * recorded in the `_migrations` table. The `_migrations` tracking table is * created idempotently first (it is also part of {@link SCHEMA_SQL}, but * we create it here so the very first migration can be recorded even when * the schema is empty). * * Each migration is applied in its own transaction; on success its name is * inserted into `_migrations`. */ private runMigrations; /** * Returns the underlying `better-sqlite3` connection. Throws if the * connection has been closed. * * @returns The active better-sqlite3 `Database` instance. */ getDb(): Database.Database; /** * Closes the database connection. Safe to call multiple times; subsequent * calls are no-ops. Throws {@link DatabaseManagerError} if the underlying * close fails. */ close(): void; /** * Whether the database connection is currently open. * * @returns `true` if the connection has not been closed. */ isOpen(): boolean; } //# sourceMappingURL=database.d.ts.map