Reputation: 13418
Is there any way to display only SQL queries on console when debugging mode is on? I want to reduce the amount of informations which is displayed.
Thanks for the help ;)
Upvotes: 23
Views: 31360
Reputation: 940
Set environment variables to configure the debug
module:
DEBUG=knex:query
for just queriesDEBUG=knex:tx
for transactionsDEBUG=knex*
for everything.Upvotes: 54
Reputation: 539
If what you need is to show the query string, one way is to register a function that logs the query data using the event 'query' that Knex emit just before executing the query.
For example:
var knex = require( 'knex' );
knex.on( 'query', function( queryData ) {
console.log( queryData );
});
After that, before every query, the anonymous function is called and queryData contains json with the information about the query.
Upvotes: 23
Reputation: 2808
Actually, if you're using MySQL, you can set
debug: ['ComQueryPacket']
as part of the config settings for mysql (not Knex).
I'll looking into adding this as an option in Knex though.
Upvotes: 7