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 ;)
How do I debug? # Knex is beginning to make use of the debug module internally, so you can set the DEBUG environment variable to knex:* to see all debugging, or select individual namespaces DEBUG=knex:query,knex:tx to constrain a bit.
Sequelize is an ORM that includes some query builder stuff; Knex is just a query builder, not an ORM.
Knex.js (pronounced /kəˈnɛks/) is a "batteries included" SQL query builder for PostgreSQL, CockroachDB, MSSQL, MySQL, MariaDB, SQLite3, Better-SQLite3, Oracle, and Amazon Redshift designed to be flexible, portable, and fun to use.
js is safe by default”
Set environment variables to configure the debug
module:
DEBUG=knex:query
for just queriesDEBUG=knex:tx
for transactionsDEBUG=knex*
for everything.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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With