/** * SMI-2182: sql.js (WASM) Driver Implementation * * Wraps the sql.js library to implement the Database abstraction interface. * This driver is used when native modules are NOT available (macOS, WebContainers). * * sql.js is a JavaScript implementation of SQLite that runs in WebAssembly. * It requires async initialization but provides cross-platform compatibility. * * Key differences from better-sqlite3: * - Async initialization (WASM loading) * - In-memory by default, manual persistence to file * - Different API for prepared statements * * @see https://github.com/sql-js/sql.js */ import type { Database, Statement, DatabaseOptions } from '../database-interface.js'; interface SqlJsDatabase { run(sql: string): void; prepare(sql: string): SqlJsStatement; export(): Uint8Array; close(): void; } interface SqlJsStatement { bind(params?: SqlJsBindParams): boolean; step(): boolean; get(): SqlJsValue[]; getColumnNames(): string[]; reset(): void; free(): void; } type SqlJsValue = string | number | null | Uint8Array; type SqlJsBindParams = SqlJsValue[] | Record; /** * Wraps a sql.js Database to implement our Database interface */ export declare class SqlJsDatabaseAdapter implements Database { private readonly db; private readonly filePath; private _open; private readonly _memory; private readonly _readonly; private _transactionDepth; constructor(db: SqlJsDatabase, filePath: string, options?: DatabaseOptions); exec(sql: string): void; prepare(sql: string): Statement; transaction(fn: (...args: Args) => T): (...args: Args) => T; pragma(pragma: string): unknown; close(): void; /** * Persist the in-memory database to file * * SMI-5997: writes atomically (temp file + rename) rather than a direct * writeFileSync to filePath. A direct write truncates the target file * before the new bytes land; a process kill/crash mid-write (OOM, SIGKILL, * machine sleep) during that window leaves a 0-byte file on disk, which * openDatabaseAsync() then silently misclassifies as a fresh/legacy import * instead of a corrupt file — see schema.ts. rename() is atomic on the * same filesystem, so the target is only ever fully-old or fully-new. */ persist(): void; /** * Export the database as a Uint8Array * Useful for manual persistence or serialization */ export(): Uint8Array; get open(): boolean; get name(): string; get memory(): boolean; get readonly(): boolean; /** * Get the underlying sql.js database instance * Use with caution - this bypasses the abstraction layer */ get native(): SqlJsDatabase; } /** * Create a database connection using sql.js (WASM) * * @param path - Path to database file, or ':memory:' for in-memory database * @param options - Database connection options * @returns Promise resolving to a Database instance wrapping sql.js * @throws Error if sql.js WASM module fails to load */ export declare function createSqlJsDatabase(path?: string, options?: DatabaseOptions): Promise; /** * Check if fts5-sql-bundle (sql.js with FTS5) is available * This always returns true in Node.js since it's a pure JS/WASM module * * Note: We use require.resolve() here instead of dynamic import() because: * 1. This is a synchronous availability check - dynamic import would require async * 2. require.resolve() is fast and doesn't load the module, just checks resolvability * 3. The actual loading in loadSqlJs() uses dynamic import() for proper ESM support * * @returns true if fts5-sql-bundle is loadable in Node.js */ export declare function isSqlJsAvailable(): boolean; export {}; //# sourceMappingURL=sqljsDriver.d.ts.map