/utils/sqlFilter

The sqlFilter module export a utility method to create SQL filter strings for SQL query templates.

Methods

(inner) addValues(val) → {number}

The addValues method is used to add values to the SQLparams array.

Parameters:
NameTypeDescription
valstring
Returns:

SQLparams.length

Type: 
number

(inner) isValidParam(val, type)

Check whether val param is of expected type.

Parameters:
NameTypeDescription
val*
typestring
Returns:

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.

Parameters:
NameTypeDescription
filterObject
Returns:

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.

Parameters:
NameTypeDescription
filterObject
paramsArray
Returns:

SQL query string

Type: 
string

Type Definitions

filterTypes

The filterTypes object contains methods for each filter type.

Type:
  • Object
Properties
NameTypeDescription
eqfunction

The value is numeric and must be equal compared with the field.

gtfunction

The value is numeric and must be greater than compared with the field.

gtefunction

The value is numeric and must be greater than or equal compared with the field.

ltfunction

The value is numeric and must be lesser than compared with the field.

ltefunction

The value is numeric and must be lesser than or equal compared with the field.

booleanfunction

The value is boolean and must be the same as IS the field.

nullfunction

The field must be NULL.

nifunction

The field must be NOT IN the value array.

infunction

The field must be IN the value array.

likefunction

The value is a string which is like the field.

matchfunction

The value is a string which must be the same as the field.

typeCheckers

Object containing type checking functions for each supported type

Type:
  • Object
Properties
NameTypeDescription
arrayfunction

The value is an array.

stringfunction

The value is typeof string.

numericfunction

The value is a number.