/utils/sqlFilter
The sqlFilter module export a utility method to create SQL filter strings for SQL query templates.
- Source
Methods
(inner) addValues(val) → {number}
The addValues method is used to add values to the SQLparams array.
Name | Type | Description |
---|---|---|
val | string |
- Source
SQLparams.length
- Type:
- number
(inner) isValidParam(val, type)
Check whether val param is of expected type.
Name | Type | Description |
---|---|---|
val | * | |
type | string |
- Source
boolean
(inner) mapFilterEntries(filter) → {string}
The mapFilterEntries method is used to map the filter entries and convert them into a SQL query string. The method also validates the filter entries against SQL parameter validation. A string match filter for the user.email is added to the filter if the filter entry value has a user property.
Name | Type | Description |
---|---|---|
filter | Object |
- Source
SQL query string
- Type:
- string
(inner) sqlfilter(filter, params) → {string}
The sqlfilter method is used to convert the filter object into a SQL query string. If the filter is an array, the filter will be conditional OR. If the filter is a string, the filter will be returned as is.
Name | Type | Description |
---|---|---|
filter | Object | |
params | Array |
- Source
SQL query string
- Type:
- string
Type Definitions
filterTypes
The filterTypes object contains methods for each filter type.
- Object
Name | Type | Description |
---|---|---|
eq | function | The value is numeric and must be equal compared with the field. |
gt | function | The value is numeric and must be greater than compared with the field. |
gte | function | The value is numeric and must be greater than or equal compared with the field. |
lt | function | The value is numeric and must be lesser than compared with the field. |
lte | function | The value is numeric and must be lesser than or equal compared with the field. |
boolean | function | The value is boolean and must be the same as IS the field. |
null | function | The field must be NULL. |
ni | function | The field must be NOT IN the value array. |
in | function | The field must be IN the value array. |
like | function | The value is a string which is like the field. |
match | function | The value is a string which must be the same as the field. |
- Source
typeCheckers
Object containing type checking functions for each supported type
- Object
Name | Type | Description |
---|---|---|
array | function | The value is an array. |
string | function | The value is typeof string. |
numeric | function | The value is a number. |
- Source