LogoLogo
9.1.0
9.1.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
      • Locks
      • 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 and Reset
      • Return Format
      • Column Formatter
      • Interception Points
    • Debugging
      • sqlCommenter
  • 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

Was this helpful?

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

Return Format

returnFormat refers to the transformation your executed query makes (if any) before being returned to you. You can choose one of three return formats:

  • "array"

  • "query"

  • "none"

  • A custom function

By default, qb returns an array of structs as the result of your query. This is the same as specifying array as your returnFormat:

config/ColdBox.cfc
moduleSettings = {
    "qb": {
        "returnFormat": "array"
    }
};

You can get the original query object that CFML generates by setting the returnFormat to query:

config/ColdBox.cfc
moduleSettings = {
    "qb": {
        "returnFormat": "query"
    }
};

This setting can be overridden on a per-instance basis by calling setReturnFormat():

setReturnFormat
var qb = wirebox.getInstance( "QueryBuilder@qb" );

qb
   .setReturnFormat( 'query' )
   .from( 'users' )
   .get()

If you want complete control over your return result, you can provide a function as a returnFormat. The results of the function will be returned as the results of the builder.

config/ColdBox.cfc
moduleSettings = {
    "qb": {
        "returnFormat": function( q ) {
            return application.wirebox.getInstance(
                "name" = "Collection",
                "initArguments" = { "collection": q }
            );
        }
    }
};
PreviousClone and ResetNextColumn Formatter

Last updated 2 years ago

Was this helpful?