From ae672e0e0a2bfd434ddc514b2a1507b3d2100053 Mon Sep 17 00:00:00 2001 From: gosho-kazuya Date: Thu, 17 Jun 2021 19:38:19 +0900 Subject: [PATCH] show bindings to logger, closes #11 --- src/index.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index da80fd5..0340873 100644 --- a/src/index.js +++ b/src/index.js @@ -23,6 +23,7 @@ const COLORIZE = { primary: chalk.magenta, error: chalk.red, success: chalk.cyan, + info: chalk.blue, } /** @@ -75,7 +76,14 @@ function makeQueryPrinter(knex: Knex, { logger, withBindings }) { return function print({ sql, bindings, duration }, colorize: Function) { const sqlRequest = formatQuery(sql, withBindings ? bindings : null) - logger('%s %s', COLORIZE.primary(`SQL (${duration.toFixed(3)} ms)`), colorize(sqlRequest)) + if (withBindings) { + // Knex 0.95.0 has a binding issue, so current workaround is to pass bindings to logger. + // Ideally we want to embed bindings into SQL, but it is not possible (as long as keeping performance). + // See: https://github.com/khmm12/knex-tiny-logger/issues/11 + logger('%s %s %s %j', COLORIZE.primary(`SQL (${duration.toFixed(3)} ms)`), colorize(sqlRequest), COLORIZE.info(`Bindings`), bindings); + } else { + logger('%s %s', COLORIZE.primary(`SQL (${duration.toFixed(3)} ms)`), colorize(sqlRequest)); + } } }