Search…
Query Options
Each query execution method allows for the passing of an options struct. This is the same struct you would pass to queryExecute.

Default Options

qb allows you to specify default options when creating the QueryBuilder instance using the defaultOptions argument. You can combine this with WireBox to create custom QueryBuilder instances pointing to different datasources and even different grammars.
When mapping to components provided by modules, such as qb, use the afterAspectsLoad interception point inside your config/WireBox.cfc to ensure all modules are fully loaded and available.
config/WireBox.cfc
1
component {
2
3
function afterAspectsLoad() {
4
binder.map( "MyCustomQueryBuilder" )
5
.to( "qb.models.Query.QueryBuilder" )
6
.initArg( name = "grammar", ref = "[email protected]" )
7
.initArg( name = "defaultOptions", value = {
8
"datasource": "my_custom_datasource"
9
} );
10
}
11
12
}
Copied!

Retrieving results from alternative datasources

In Application.cfc you can specify your default datasource which will be used by qb. If you want to retrieve data from other datasources you can specify this in all retrieval functions by using the extra options parameter such as:
QueryBuilder
1
query.from( "users" )
2
.get( options = { datasource: "MyOtherDatasourceName" } );
Copied!
If you also want to use a non-default SQL Grammar you have to specify this when creating your QueryBuilder.
QueryBuilder
1
var query = wirebox.getInstance( "[email protected]" )
2
.setGrammar( wirebox.getInstance( "[email protected]" ) );
Copied!
Last modified 1yr ago