rizidoro
rizidoro

Reputation: 13418

knex.js - debug only SQL

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

Answers (3)

timruffs
timruffs

Reputation: 940

Set environment variables to configure the debug module:

  • DEBUG=knex:query for just queries
  • DEBUG=knex:tx for transactions
  • and DEBUG=knex* for everything.

Upvotes: 54

Emanuele Benedetti
Emanuele Benedetti

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

tgriesser
tgriesser

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

Related Questions