Debugging

Debugging a Single Query

toSQL

Name

Type

Required

Default

Description

showBindings

boolean

false

false

If true, the bindings for the query will be substituted back in where the question marks (?) appear.

Returns the SQL that would be executed for the current query.

var userQuery = getInstance( "User" )
    .where( "active", "=", 1 );

writeOutput( userQuery.toSQL() );
SELECT `users`.`id`, `users`.`username` /* etc */
FROM "users"
WHERE "active" = ?

The bindings for the query are represented by question marks (?) just as when using queryExecute. qb can replace each question mark with the corresponding cfqueryparam-compatible struct by passing showBindings = true to the method.

var userQuery = getInstance( "User" )
    .where( "active", "=", 1 );

writeOutput( userQuery.toSQL( showBindings = true ) );
Result
SELECT `users`.`id`, `users`.`username` /* etc */
FROM "users"
WHERE "active" = {"value":1,"cfsqltype":"CF_SQL_NUMERIC","null":false}

tap

Name

Type

Required

Default

Description

callback

Function

true

A function to execute with an instance of the current entity.

Executes a callback with the current entity passed to it. The return value from tap is ignored and the current entity is returned.

While not strictly a debugging method, tap makes it easy to see the changes to an entity after each call without introducing temporary variables.

getInstance( "User" )
    .tap( function( e ) {
        writeOutput( e.toSQL() & "<br>" );
    } )
    .where( "active", "=", 1 )
    .tap( function( e ) {
        writeOutput( e.toSQL() & "<br>" );
    } );
SELECT `users`.`id`, `users`.`username` /* etc */ FROM "users"
SELECT `users`.`id`, `users`.`username` /* etc */ FROM "users" WHERE "active" = ?

Debugging All Queries

cbDebugger

Additionally, with Quick installed you will see number of loaded entities for the request. This can help identify places that are missing pagination or relationships that could be tuned or converted to a subselect.

LogBox Appender

Quick is set to log all queries to a debug log out of the box via qb. To enable this behavior, configure LogBox to allow debug logging from qb's grammar classes.

config/ColdBox.cfc
logbox = {
    debug = [ "qb.models.Grammars" ]
};

Interception Points

Last updated

Was this helpful?