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