Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I view the query `knex` builds?

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',
    }); 
like image 225
Dan Avatar asked Apr 30 '18 08:04

Dan


People also ask

What does KNEX query return?

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] .

What is KNEX query?

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.

What is query Builder?

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?

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.


1 Answers

http://knexjs.org/#Interfaces-toSQL

knex('statistics')
    .del()
    .where({
        'stats': 'reddit',
    }).toSQL().toNative()
like image 164
Mikael Lepistö Avatar answered Sep 22 '22 22:09

Mikael Lepistö