u
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
*/
|
||||
|
||||
import Database from 'better-sqlite3';
|
||||
import { logSlowQuery } from '../provider.js';
|
||||
import { SCHEMA_SCRIPTS } from './schema.js';
|
||||
|
||||
function normalizeParamValue(value) {
|
||||
@@ -236,24 +237,29 @@ export class BetterSqlite3Executor {
|
||||
|
||||
/** @returns {Promise<import('../provider.js').QueryResult>} */
|
||||
async query(sql, params = {}) {
|
||||
const statement = this.db.prepare(sql);
|
||||
const bindings = bindParams(params, sql);
|
||||
const start = performance.now();
|
||||
try {
|
||||
const statement = this.db.prepare(sql);
|
||||
const bindings = bindParams(params, sql);
|
||||
|
||||
if (statement.reader) {
|
||||
const rows = statement.all(bindings);
|
||||
if (statement.reader) {
|
||||
const rows = statement.all(bindings);
|
||||
return {
|
||||
rows,
|
||||
rowsAffected: rows.length,
|
||||
insertId: normalizeInsertId(rows[0]?.id),
|
||||
};
|
||||
}
|
||||
|
||||
const result = statement.run(bindings);
|
||||
return {
|
||||
rows,
|
||||
rowsAffected: rows.length,
|
||||
insertId: normalizeInsertId(rows[0]?.id),
|
||||
rows: [],
|
||||
rowsAffected: result.changes,
|
||||
insertId: normalizeInsertId(result.lastInsertRowid),
|
||||
};
|
||||
} finally {
|
||||
logSlowQuery(sql, performance.now() - start, params);
|
||||
}
|
||||
|
||||
const result = statement.run(bindings);
|
||||
return {
|
||||
rows: [],
|
||||
rowsAffected: result.changes,
|
||||
insertId: normalizeInsertId(result.lastInsertRowid),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user