mirror of
https://github.com/BetterCorp/BetterFrame.git
synced 2026-05-26 17:56:34 +00:00
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:
parent
6df11b6c18
commit
4062b8bb6f
1 changed files with 7 additions and 3 deletions
|
|
@ -40,9 +40,13 @@ export class SqliteAdapter implements DbAdapter {
|
||||||
return s;
|
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> {
|
async run(sql: string, params: ReadonlyArray<SqlValue> = []): Promise<RunResult> {
|
||||||
const stmt = this.prep(sql);
|
const stmt = this.prep(sql);
|
||||||
const r = stmt.run(...(params as any[]));
|
const r = stmt.run(...this.coerce(params));
|
||||||
return {
|
return {
|
||||||
lastInsertRowid:
|
lastInsertRowid:
|
||||||
typeof r.lastInsertRowid === "bigint" ? r.lastInsertRowid : BigInt(r.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> {
|
async get<T = Row>(sql: string, params: ReadonlyArray<SqlValue> = []): Promise<T | undefined> {
|
||||||
const stmt = this.prep(sql);
|
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;
|
return r as T | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
async all<T = Row>(sql: string, params: ReadonlyArray<SqlValue> = []): Promise<T[]> {
|
async all<T = Row>(sql: string, params: ReadonlyArray<SqlValue> = []): Promise<T[]> {
|
||||||
const stmt = this.prep(sql);
|
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> {
|
async exec(sql: string): Promise<void> {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue