Skip to content

Commit

Permalink
feat: associate every query with an incremental ID
Browse files Browse the repository at this point in the history
  • Loading branch information
gajus committed Nov 1, 2017
1 parent 0a6e293 commit b4513d3
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,15 @@ const log = Logger.child({
namespace: 'mightyql'
});

let queryId = 0;

export const query: InternalQueryType<*> = async (connection, rawSql, values) => {
const strippedSql = stripComments(rawSql);

queryId++;

log.debug({
queryId,
sql: strippedSql
}, 'input query');

Expand Down Expand Up @@ -97,12 +102,18 @@ export const query: InternalQueryType<*> = async (connection, rawSql, values) =>

const end = process.hrtime(start);

log.trace('query execution time %s', prettyHrtime(end));
log.trace({
queryId
}, 'query execution time %s', prettyHrtime(end));

if (result.rowCount) {
log.trace('query returned %d row(s)', result.rowCount);
log.trace({
queryId
}, 'query returned %d row(s)', result.rowCount);
} else if (Array.isArray(result)) {
log.trace('query returned %d row(s)', result.length);
log.trace({
queryId
}, 'query returned %d row(s)', result.length);
}

return result;
Expand Down

0 comments on commit b4513d3

Please sign in to comment.