Skip to content

Commit

Permalink
feat(QueryBuilder): Use array returntype where available
Browse files Browse the repository at this point in the history
  • Loading branch information
elpete committed Apr 30, 2019
1 parent 6a5b550 commit 2c45627
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion models/Query/QueryBuilder.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ component displayname="QueryBuilder" accessors="true" {
*/
property name="returnFormat";

/**
* returnFormatType string
* Used to take advantage of Lucee's native support.
* @default "array"
*/
property name="returnFormatType";

/**
* columnFormatter callback
* If provided, each column is passed to it before being added to the query.
Expand Down Expand Up @@ -2416,7 +2423,7 @@ component displayname="QueryBuilder" accessors="true" {
return;
}

if ( isQuery( q ) ) {
if ( isQuery( q ) || isArray( q ) ) {
return returnFormat( q );
}

Expand All @@ -2443,6 +2450,9 @@ component displayname="QueryBuilder" accessors="true" {
string returnObject = "query",
any clearExcept = []
) {
if ( variables.returnFormatType != "" ) {
options[ "returntype" ] = variables.returnFormatType;
}
var result = grammar.runQuery( sql, getBindings(), options, returnObject );
clearBindings( except = arguments.clearExcept );
if ( ! isNull( result ) ) {
Expand Down Expand Up @@ -2509,11 +2519,16 @@ component displayname="QueryBuilder" accessors="true" {
* @return qb.models.Query.QueryBuilder
*/
public QueryBuilder function setReturnFormat( required any format ) {
variables.returnFormatType = "";
if ( isClosure( arguments.format ) || isCustomFunction( arguments.format ) ) {
variables.returnFormat = format;
}
else if ( arguments.format == "array" ) {
variables.returnFormatType = "array";
variables.returnFormat = function( q ) {
if ( isArray( q ) ) {
return q;
}
return getUtils().queryToArrayOfStructs( q );
};
}
Expand Down

0 comments on commit 2c45627

Please sign in to comment.