This commit is contained in:
seb
2026-10-12 22:32:21 +02:00
parent 28e62093b3
commit 8a8aeaedd7
21 changed files with 786 additions and 4 deletions

View File

@@ -19,13 +19,23 @@ function normalizeParamValue(value) {
return value;
}
function bindParams(params) {
return Object.fromEntries(
function bindParams(params, sql = null) {
const bound = Object.fromEntries(
Object.entries(params).map(([key, value]) => [
key.replace(/^[@:$]/, ''),
normalizeParamValue(value),
]),
);
if (typeof sql === 'string') {
const matches = sql.matchAll(/[@:$]([a-zA-Z0-9_]+)/g);
for (const match of matches) {
const name = match[1];
if (!(name in bound)) {
bound[name] = null;
}
}
}
return bound;
}
function normalizeInsertId(value) {
@@ -227,7 +237,7 @@ export class BetterSqlite3Executor {
/** @returns {Promise<import('../provider.js').QueryResult>} */
async query(sql, params = {}) {
const statement = this.db.prepare(sql);
const bindings = bindParams(params);
const bindings = bindParams(params, sql);
if (statement.reader) {
const rows = statement.all(bindings);