19

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 ;)

rizidoro
  • 13,073
  • 18
  • 59
  • 86

3 Answers3

51

Set environment variables to configure the debug module:

  • DEBUG=knex:query for just queries
  • DEBUG=knex:tx for transactions
  • and DEBUG=knex* for everything.
timruffs
  • 910
  • 8
  • 9
21

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.

7

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.

tgriesser
  • 2,808
  • 1
  • 22
  • 22