BoxLang 🚀 A New JVM Dynamic Language Learn More...
The Model Utility is a module that will simplify the use of Models by providing common functionality and actions done on a model. ...
Get a copy of the module into your project
box install model-utility
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.
This Module asumes that you are familiar with the ColdBox Framework architecture.
Step 1: Instanciate your Model from your newly installed Module Create a new property and inject the model of your choice. The pattern to inject its value is in this manner [Model]@[Module]
property name='modelUtility' inject='ModelUtility@model-utility'
Step 3: call the print() method and pass your data. Once your property has been declared and injected with the model, you are ready to use it, here is and example of the minimum required parameters you need to pass:
modelUtility.[desiredfunction]([neded parameters]);
The original function is still valid and will continue to work. It takes 3 parameters: createQueryFilters()
- allowedFilters,
- providedFilters,
- specialFilters
The new function allows more parameters and configuration, as well as more flexibility and capabilities.
queryHelper()
It takes a single struct (queryConfig) with partial or full configuration
var defaultConfig = {
'allowedFilters' : {},
'providedFilters' : {},
'extra' : {
'dateRange' : {},
'filtersApproved' : [],
'filtersRejected' : [],
'sqlClauses' : {},
'sqlSpecialClauses' : {},
'specialFilters' : {}
},
'autoExecute' : false,
'baseSql' : '',
'dateRange' : {},
'options' : {}
};
You will get the following results
var result = {
'sql' : '',
'params' : {},
'options' : {},
'extra' : {}
}
Here is an example:
var queryConfig = {
// 'autoExecute' : true,
// 'baseSql' : baseSql,
// 'name' : 'testing',
// 'dateRange' : {
// 'start' : '2010-01-27',
// 'end' : '2010-01-28',
// // 'preset' : 'today'
// },
// 'options' : {
// // // 'cachedWithin' : createTimespan( 0, 1, 0, 0 ),
// 'dataSource' : dsn.name
// // 'returnType' : 'array'
// },
// 'specialFilters' : [ ' AND rownum = 1 ' ],
'allowedFilters' : variables.allowedFilters,
'providedFilters' : arguments.filters
};
It has a configuration for autoExecute key, which, when set to true. It will return the actual executed query
$
box install model-utility