Skip to content

Commit

Permalink
feat: measure query execution time
Browse files Browse the repository at this point in the history
  • Loading branch information
gajus committed Mar 25, 2017
1 parent 9fa1887 commit 40f223c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"debug": "^2.6.3",
"es6-error": "^4.0.2",
"mysql2": "^1.2.0",
"pretty-hrtime": "^1.0.3",
"sqlstring": "^2.2.0"
},
"description": "A higher-level abstraction of the node-mysql2 driver with Flowtype and convenience methods for common operations.",
Expand Down
11 changes: 10 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import SqlString from 'sqlstring';
import createDebug from 'debug';
import prettyHrtime from 'pretty-hrtime';
import {
createPool as createPool2
} from 'mysql2/promise';
Expand Down Expand Up @@ -34,7 +35,15 @@ export const query: InternalQueryType = async (connection, sql, values) => {

debug('query', formattedSql);

return connection.query(formattedSql);
const start = process.hrtime();

const result = await connection.query(formattedSql);

const end = process.hrtime(start);

debug('query execution time', prettyHrtime(end));

return result;
};

export const insert: InternalQueryInsertType = async (connection, sql, values) => {
Expand Down

0 comments on commit 40f223c

Please sign in to comment.