/** * The three operations every SQLite adapter needs. * * Injected rather than imported, so no SQLite driver becomes a dependency of this package. Each may * answer synchronously or with a promise, which is what lets one contract cover both the synchronous * drivers — `node:sqlite` and `better-sqlite3` — and the asynchronous libSQL client. */ export interface SqliteLikeClient { /** Runs a statement that returns no rows, reporting how many rows it changed. */ run(sql: string, params?: readonly SqliteValue[]): { changes: number; } | Promise<{ changes: number; }>; /** Runs a query and returns its rows as objects keyed by column name. */ all(sql: string, params?: readonly SqliteValue[]): unknown[] | Promise; /** Runs one or more statements with no parameters, such as a migration. */ exec(sql: string): unknown; } /** * A value bound to a SQLite parameter. Adapters only ever bind these; bytes are bound as a blob, which * is how the vector store keeps embeddings compact. */ export type SqliteValue = string | number | null | Uint8Array; /** * The part of a synchronous SQLite handle the adapters need: `node:sqlite`'s `DatabaseSync` and * `better-sqlite3`'s `Database` both provide it. */ export interface SqliteDatabaseLike { /** Prepares a statement. */ prepare(sql: string): { run(...params: SqliteValue[]): { changes: number | bigint; }; all(...params: SqliteValue[]): unknown[]; }; /** Runs statements with no parameters. */ exec(sql: string): unknown; } /** The part of a libSQL client the adapters need: `execute()` with positional arguments. */ export interface LibsqlLikeClient { /** Runs one statement. */ execute(statement: { sql: string; args: SqliteValue[]; }): Promise<{ rows: unknown[]; rowsAffected: number; }>; /** Runs statements with no parameters. */ executeMultiple(sql: string): Promise; } /** * Adapts a synchronous handle — `new DatabaseSync(path)` from `node:sqlite`, or `new Database(path)` * from `better-sqlite3` — to the client contract. Prepared statements are cached per SQL text, so a * statement an adapter runs on every call is compiled once. */ export declare function fromSqliteDatabase(db: SqliteDatabaseLike): SqliteLikeClient; /** Adapts a libSQL or Turso client to the client contract. */ export declare function fromLibsql(client: LibsqlLikeClient): SqliteLikeClient; /** Accepts either a client or a synchronous handle, so the common case needs no adapter call. */ export declare function toSqliteClient(source: SqliteLikeClient | SqliteDatabaseLike): SqliteLikeClient; /** A table name, quoted. Letters, digits, and underscores only, so a table option can never inject SQL. */ export declare function quoteSqliteTable(name: string): string; /** Whether an error is SQLite refusing a duplicate key. */ export declare function isSqliteUniqueViolation(error: unknown): boolean;