@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.
package/dist/index.js CHANGED
@@ -3920,11 +3920,31 @@ var Db = class _Db {
3920
3920
  }
3921
3921
  this.queriesLog = [];
3922
3922
  this.knexInstance.queriesLog = this.queriesLog;
3923
+ const startsByConnection = /* @__PURE__ */ new Map();
3924
+ const pushStart = (query) => {
3925
+ const uid = query?.__knexUid ?? "";
3926
+ if (!startsByConnection.has(uid)) {
3927
+ startsByConnection.set(uid, []);
3928
+ }
3929
+ startsByConnection.get(uid).push(process.hrtime());
3930
+ };
3931
+ const popStart = (query) => {
3932
+ const uid = query?.__knexUid ?? "";
3933
+ const stack = startsByConnection.get(uid);
3934
+ if (!stack?.length) {
3935
+ return null;
3936
+ }
3937
+ return stack.pop();
3938
+ };
3923
3939
  this.knexInstance.on("query", (query) => {
3924
- query.__startTime = process.hrtime();
3940
+ pushStart(query);
3925
3941
  });
3926
3942
  this.knexInstance.on("query-response", (_response, query) => {
3927
- const [seconds, nanoseconds] = process.hrtime(query.__startTime);
3943
+ const start = popStart(query);
3944
+ if (!start) {
3945
+ return;
3946
+ }
3947
+ const [seconds, nanoseconds] = process.hrtime(start);
3928
3948
  const executionTimeMs = (seconds * 1e3 + nanoseconds / 1e6).toFixed(2);
3929
3949
  const logEntry = {
3930
3950
  sql: query.sql,
@@ -3935,6 +3955,7 @@ var Db = class _Db {
3935
3955
  this.logger.debug?.(`[Db] Query: ${query.sql} | Duration: ${executionTimeMs}ms`);
3936
3956
  });
3937
3957
  this.knexInstance.on("query-error", (error, query) => {
3958
+ popStart(query);
3938
3959
  this.logger.error?.(`[Db] Query failed: ${query.sql}`, error);
3939
3960
  });
3940
3961
  }