For debugging purposes, I want to see the SQL query knex
is executing. For example, I want to view SQL that knex
produces for this code:
knex('statistics')
.del()
.where({
'stats': 'reddit',
});
Knex returns an array for all queries, even if there is only one row returned. The name of the user can be accessed from user[0] .
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.
Query Builder is designed to enhance productivity and simplify SQL query building tasks. Query Builder provides a graphical user interface for creating SQL queries. You can drag-and-drop multiple tables, views and their columns onto a visual designer to generate SQL statements.
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.
http://knexjs.org/#Interfaces-toSQL
knex('statistics')
.del()
.where({
'stats': 'reddit',
}).toSQL().toNative()
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