@nmakarov/cli-toolkit 0.37.0 → 0.39.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3247,11 +3247,31 @@ var Db = class _Db {
3247
3247
  }
3248
3248
  this.queriesLog = [];
3249
3249
  this.knexInstance.queriesLog = this.queriesLog;
3250
+ const startsByConnection = /* @__PURE__ */ new Map();
3251
+ const pushStart = (query) => {
3252
+ const uid = query?.__knexUid ?? "";
3253
+ if (!startsByConnection.has(uid)) {
3254
+ startsByConnection.set(uid, []);
3255
+ }
3256
+ startsByConnection.get(uid).push(process.hrtime());
3257
+ };
3258
+ const popStart = (query) => {
3259
+ const uid = query?.__knexUid ?? "";
3260
+ const stack = startsByConnection.get(uid);
3261
+ if (!stack?.length) {
3262
+ return null;
3263
+ }
3264
+ return stack.pop();
3265
+ };
3250
3266
  this.knexInstance.on("query", (query) => {
3251
- query.__startTime = process.hrtime();
3267
+ pushStart(query);
3252
3268
  });
3253
3269
  this.knexInstance.on("query-response", (_response, query) => {
3254
- const [seconds, nanoseconds] = process.hrtime(query.__startTime);
3270
+ const start = popStart(query);
3271
+ if (!start) {
3272
+ return;
3273
+ }
3274
+ const [seconds, nanoseconds] = process.hrtime(start);
3255
3275
  const executionTimeMs = (seconds * 1e3 + nanoseconds / 1e6).toFixed(2);
3256
3276
  const logEntry = {
3257
3277
  sql: query.sql,
@@ -3262,6 +3282,7 @@ var Db = class _Db {
3262
3282
  this.logger.debug?.(`[Db] Query: ${query.sql} | Duration: ${executionTimeMs}ms`);
3263
3283
  });
3264
3284
  this.knexInstance.on("query-error", (error, query) => {
3285
+ popStart(query);
3265
3286
  this.logger.error?.(`[Db] Query failed: ${query.sql}`, error);
3266
3287
  });
3267
3288
  }