fix(db): SQLite adapter coerce true/false to 1/0 in params

node:sqlite rejects JS booleans as bind params. SQLite adapter now
converts true→1, false→0 before binding. Mirrors the PG compat
approach from the other direction.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Mitchell R 2026-05-24 02:29:46 +02:00
parent 6df11b6c18
commit 4062b8bb6f
No known key found for this signature in database

View file

@ -40,9 +40,13 @@ export class SqliteAdapter implements DbAdapter {
return s;
}
private coerce(params: ReadonlyArray<SqlValue>): any[] {
return params.map((v) => (v === true ? 1 : v === false ? 0 : v));
}
async run(sql: string, params: ReadonlyArray<SqlValue> = []): Promise<RunResult> {
const stmt = this.prep(sql);
const r = stmt.run(...(params as any[]));
const r = stmt.run(...this.coerce(params));
return {
lastInsertRowid:
typeof r.lastInsertRowid === "bigint" ? r.lastInsertRowid : BigInt(r.lastInsertRowid),
@ -52,13 +56,13 @@ export class SqliteAdapter implements DbAdapter {
async get<T = Row>(sql: string, params: ReadonlyArray<SqlValue> = []): Promise<T | undefined> {
const stmt = this.prep(sql);
const r = stmt.get(...(params as any[]));
const r = (stmt.get as any)(...this.coerce(params));
return r as T | undefined;
}
async all<T = Row>(sql: string, params: ReadonlyArray<SqlValue> = []): Promise<T[]> {
const stmt = this.prep(sql);
return stmt.all(...(params as any[])) as T[];
return (stmt.all as any)(...this.coerce(params)) as T[];
}
async exec(sql: string): Promise<void> {