u
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user