Search code examples
javascriptknex.js

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',
    }); 

Solution

  • https://knexjs.org/guide/interfaces.html#other

    knex('statistics')
        .del()
        .where({
            'stats': 'reddit',
        }).toSQL().toNative()