This commit is contained in:
seb
2026-10-13 12:19:35 +02:00
parent 2ef2c0edbf
commit a5886b7c92
4 changed files with 85 additions and 42 deletions

View File

@@ -46,3 +46,22 @@ export function isForeignKeyConstraintError(err) {
err?.code === 'SQLITE_CONSTRAINT_FOREIGNKEY'
);
}
export const SLOW_QUERY_THRESHOLD_MS = 20;
/**
* Logs a SQL statement to the console if execution time exceeded SLOW_QUERY_THRESHOLD_MS (20ms).
*
* @param {string} sql
* @param {number} durationMs
* @param {object} [params]
*/
export function logSlowQuery(sql, durationMs, params = null) {
if (durationMs > SLOW_QUERY_THRESHOLD_MS) {
const timeStr = `${durationMs.toFixed(1)}ms`;
console.log(`[SQL >20ms] (${timeStr})\n${typeof sql === 'string' ? sql.trim() : sql}`);
if (params && Object.keys(params).length > 0) {
console.log('Params:', params);
}
}
}