LogoLogo
8.4.0
8.4.0
  • Introduction
  • What's New?
  • Installation & Usage
  • Migration Guide
  • Contributing & Filing Issues
  • Query Builder
    • Getting a New Query
    • Building Queries
      • Selects
      • From
      • Joins
      • Wheres
      • Order By
      • Group By and Having
      • Limit, Offset, and Pagination
      • Unions
      • Common Table Expressions (i.e. CTEs)
      • Raw Expressions
      • When / Conditionals
      • Query Parameters and Bindings
    • Executing Queries
      • Retrieving Results
      • Aggregates
      • Inserts, Updates, and Deletes
    • Options and Utilities
      • Query Options
      • Clone
      • Return Format
      • Column Formatter
      • Parent Query
      • Interception Points
    • Debugging
  • Schema Builder
    • Overview
    • Create
    • Columns
    • Column Modifiers
    • Column Constraints
    • Creating Table Constraints
    • Alter
    • Drop
  • External Links
    • API Docs
    • Source Code
    • Issue Tracker
Powered by GitBook
On this page
  • Default Options
  • Retrieving results from alternative datasources

Was this helpful?

Edit on Git
Export as PDF
  1. Query Builder
  2. Options and Utilities

Query Options

PreviousOptions and UtilitiesNextClone

Last updated 4 years ago

Was this helpful?

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

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 interception point inside your config/WireBox.cfc to ensure all modules are fully loaded and available.

config/WireBox.cfc
component {

    function afterAspectsLoad() {
        binder.map( "MyCustomQueryBuilder" )
            .to( "qb.models.Query.QueryBuilder" )
            .initArg( name = "grammar", ref = "AutoDiscover@qb" )
            .initArg( name = "defaultOptions", value = {
                "datasource": "my_custom_datasource" 
            } );
    }

}

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
query.from( "users" )
    .get( options = { datasource: "MyOtherDatasourceName" } );

If you also want to use a non-default SQL Grammar you have to specify this when creating your QueryBuilder.

QueryBuilder
var query = wirebox.getInstance( "QueryBuilder@qb" )
    .setGrammar( wirebox.getInstance( "MSSQLGrammar@qb" ) );
queryExecute
afterAspectsLoad