Skip to content

Commit 87b31a0

Browse files
committed
Simplify return formatter options
1 parent c8cb3c8 commit 87b31a0

4 files changed

Lines changed: 28 additions & 43 deletions

File tree

ModuleConfig.cfc

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@ component {
77
this.cfmapping = "qb";
88

99
function configure() {
10-
settings = {
11-
"defaultGrammar": "AutoDiscover@qb",
12-
"defaultReturnFormat": "array",
13-
"defaultReturnFormatOptions": {},
14-
"preventDuplicateJoins": false,
10+
settings = {
11+
"defaultGrammar": "AutoDiscover@qb",
12+
"defaultReturnFormat": "array",
13+
"preventDuplicateJoins": false,
1514
"validateOperatorsAndCombinators": true,
1615
"validateQueryExecuteReturnType": false,
1716
"collectQueryLog": true,
@@ -77,11 +76,10 @@ component {
7776
.initArg( name = "returnFormatterRegistry", ref = "ReturnFormatterRegistry@qb" )
7877
.initArg( name = "preventDuplicateJoins", value = settings.preventDuplicateJoins )
7978
.initArg( name = "validateOperatorsAndCombinators", value = settings.validateOperatorsAndCombinators )
80-
.initArg( name = "validateQueryExecuteReturnType", value = settings.validateQueryExecuteReturnType )
81-
.initArg( name = "collectQueryLog", value = settings.collectQueryLog )
82-
.initArg( name = "returnFormat", value = settings.defaultReturnFormat )
83-
.initArg( name = "defaultReturnFormatOptions", value = settings.defaultReturnFormatOptions )
84-
.initArg( name = "defaultOptions", value = settings.defaultOptions )
79+
.initArg( name = "validateQueryExecuteReturnType", value = settings.validateQueryExecuteReturnType )
80+
.initArg( name = "collectQueryLog", value = settings.collectQueryLog )
81+
.initArg( name = "returnFormat", value = settings.defaultReturnFormat )
82+
.initArg( name = "defaultOptions", value = settings.defaultOptions )
8583
.initArg( name = "sqlCommenter", ref = "ColdBoxSQLCommenter@qb" )
8684
.initArg( name = "shouldMaxRowsOverrideToAll", value = settings.shouldMaxRowsOverrideToAll );
8785

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,31 @@
11
component accessors="true" {
22

33
property name="utils";
4+
property name="options";
45

5-
public StructFormatter function init( any utils = new qb.models.Query.QueryUtils() ) {
6+
public StructFormatter function init( any utils = new qb.models.Query.QueryUtils(), struct options = {} ) {
67
variables.utils = arguments.utils;
8+
variables.options = arguments.options;
79
return this;
810
}
911

1012
public function toFormatter( struct options = {} ) {
11-
return new qb.models.Query.Formatters.StructReturnFormatter( variables.utils, arguments.options );
13+
return new qb.models.Query.Formatters.StructFormatter( utils = variables.utils, options = arguments.options );
14+
}
15+
16+
public struct function format( required any q ) {
17+
if (
18+
!variables.options.keyExists( "columnKey" ) || isNull( variables.options.columnKey ) || !len(
19+
variables.options.columnKey
20+
)
21+
) {
22+
throw(
23+
type = "MissingColumnKey",
24+
message = "A columnKey option is required for the [struct] return formatter."
25+
);
26+
}
27+
28+
return variables.utils.queryToStructOfStructs( arguments.q, variables.options.columnKey );
1229
}
1330

1431
}

models/Query/Formatters/StructReturnFormatter.cfc

Lines changed: 0 additions & 27 deletions
This file was deleted.

models/Query/QueryBuilder.cfc

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,6 @@ component displayname="QueryBuilder" accessors="true" {
301301
* Default: qb.models.Query.QueryUtils
302302
* @returnFormat The closure (or string format shortcut) that modifies the query
303303
* and is eventually returned to the caller. Default: 'array'
304-
* @defaultReturnFormatOptions Options passed to the default return formatter.
305-
* Default: {}
306304
* @returnFormatterRegistry Registry used to resolve named return formatters.
307305
* @preventDuplicateJoins Whether QB should ignore a .join() statement that matches an existing join
308306
* Default: false
@@ -333,7 +331,6 @@ component displayname="QueryBuilder" accessors="true" {
333331
grammar = new qb.models.Grammars.BaseGrammar(),
334332
utils = new qb.models.Query.QueryUtils(),
335333
returnFormat = "array",
336-
struct defaultReturnFormatOptions = {},
337334
returnFormatterRegistry,
338335
preventDuplicateJoins = false,
339336
validateOperatorsAndCombinators = true,
@@ -367,7 +364,7 @@ component displayname="QueryBuilder" accessors="true" {
367364
setParentQuery( arguments.parentQuery );
368365
}
369366
param variables.defaultOptions = {};
370-
setReturnFormat( arguments.returnFormat, arguments.defaultReturnFormatOptions );
367+
setReturnFormat( arguments.returnFormat );
371368
mergeDefaultOptions( arguments.defaultOptions );
372369
setSqlCommenter( arguments.sqlCommenter );
373370
setCollectQueryLog( arguments.collectQueryLog );

0 commit comments

Comments
 (0)