Module: jsDataQuery

Provides utility functions to filter data and to create sql condition over database.
Every function returns a function f where:
  • f ( r, environment ) = true if r matches condition in the given environment
  • f( r, environment ) = result evaluated in the given environment if f is a computation function
  • f.isTrue = true if f is always true
  • f.isFalse = true if f is always false
  • f ( r, environment) = undefined if there is no sufficient data to evaluate f
null fields and undefined fields are all considered (and returned) as null values (so they compare equal).
f.toSql(formatter, environment) = a string representing the underlying condition to be applied to a database. formatter is used to obtain details about the sql dialect to use, see [sqlFormatter](jsSqlServerFormatter.js) for an example
[environment] is the environment into which the expression have to be evaluated
Source:

Methods

(inner) and(arr) → {sqlFun}

checks if all supplied expression evaluate to truthy values
Parameters:
Name Type Description
arr Array.<sqlFun> | Array.<object> array or list of expression
Source:
Returns:
Type
sqlFun

(inner) between(expr1, min, max) → {sqlFun}

Check if expr1 evaluates between min and max
Parameters:
Name Type Description
expr1 sqlFun | string | object note: this is autofield-ed, so if you can use a field name for it
min sqlFun | object
max sqlFun | object
Source:
Returns:
Type
sqlFun

(inner) bitClear(expression, nbit) → {sqlFun}

Check if the nth bit of expression is not set
Parameters:
Name Type Description
expression sqlFun | string note: this is autofield-ed, so if you can use a field name for it
nbit sqlFun | object
Source:
Returns:
Type
sqlFun

(inner) bitSet(expression, nbit) → {sqlFun}

Check if the nth bit of expression is set
Parameters:
Name Type Description
expression sqlFun | string | object note: this is autofield-ed, so if you can use a field name for it
nbit sqlFun | object
Source:
Returns:
Type
sqlFun

(inner) bitwiseAnd(arr) → {sqlFun}

Parameters:
Name Type Description
arr Array.<sqlFun> | Array.<object> array or list of expression
Source:
Returns:
Type
sqlFun

(inner) bitwiseNot(expression) → {sqlFun}

Parameters:
Name Type Description
expression sqlFun | string | object | function note: this is auto-field, so if you can use a field name for it
Source:
Returns:
Type
sqlFun

(inner) bitwiseOr(arr) → {sqlFun}

Parameters:
Name Type Description
arr Array.<sqlFun> | Array.<object> array or list of expression
Source:
Returns:
Type
sqlFun

(inner) bitwiseXor(arr) → {sqlFun}

Parameters:
Name Type Description
arr Array.<sqlFun> | Array.<object> array or list of expression
Source:
Returns:
Type
sqlFun

(inner) calc(expr, r, environment) → {Object|string|null|undefined}

Evaluates an expression in a given environment
Parameters:
Name Type Description
expr function representing a generic expression
r object
environment Environment
Source:
Returns:
expr(r) evaluated in the given environment undefined are returned as null constant
Type
Object | string | null | undefined

(inner) concat(values) → {sqlFun}

returns a functions that evaluates the concatenation of a list or array of strings given when it is CREATED
Parameters:
Name Type Description
values Array.<sqlFun> | Array.<object>
Source:
Returns:
Type
sqlFun

(inner) constant(value) → {sqlFun}

Defines a constant function. The toSql method invokes the formatter.quote function
Parameters:
Name Type Description
value object is a literal
Source:
Returns:
f such that f()= k, f.toSql()= formatter.quote(k)
Type
sqlFun

(inner) context(environmentVariable) → {sqlFun}

Transforms a generic function into a sqlFun, returning a similar function with some additional methods
Parameters:
Name Type Description
environmentVariable string | function Environment variable path or function
Source:
Returns:
Type
sqlFun
Example
if environment = {a:1, b:2} and environmentFunction = function (env){return env.a}
  context(environmentFunction) applied to environment will return 1

(inner) convertToInt(expr1) → {sqlFun}

Converts a generic expression into an integer
Parameters:
Name Type Description
expr1 sqlFun | string | object
Source:
Returns:
Type
sqlFun

(inner) convertToString(expr1, maxLen) → {sqlFun}

Converts a generic expression into a string
Parameters:
Name Type Description
expr1 sqlFun | string | object
maxLen int maximum string len
Source:
Returns:
Type
sqlFun

(inner) distinctVal(arr, fieldname) → {Array.<object>|undefined}

Finds distinct values of a field
Parameters:
Name Type Description
arr Array.<object>
fieldname
Source:
Returns:
Type
Array.<object> | undefined

(inner) distinctVal(exprList) → {sqlFun}

Finds distinct values of a list of fields
Parameters:
Name Type Description
exprList Array.<(sqlFun|object)>
Source:
Returns:
Type
sqlFun

(inner) div(expr1, expr2) → {sqlFun}

returns a functions that does a division
Parameters:
Name Type Description
expr1 sqlFun | string | object
expr2 sqlFun | object
Source:
Returns:
Type
sqlFun

(inner) doPar(expr) → {sqlFun}

returns the result of internal expression
Parameters:
Name Type Description
expr sqlFun | string | object
Source:
Returns:
Type
sqlFun

(inner) eq(expr1, expr2) → {sqlFun}

checks if expr1 evaluates equal to expr2
Parameters:
Name Type Description
expr1 sqlFun | string | object note: this is autofield-ed, so if you can use a field name for it
expr2 sqlFun | object
Source:
Returns:
Type
sqlFun

(inner) ge(expr1, expr2) → {sqlFun}

checks if expr1 evaluates greater than or equal to expr2
Parameters:
Name Type Description
expr1 sqlFun | string | object note: this is autofield-ed, so if you can use a field name for it
expr2 sqlFun | object
Source:
Returns:
Type
sqlFun

(inner) gt(expr1, expr2) → {sqlFun}

checks if expr1 evaluates greater than expr2
Parameters:
Name Type Description
expr1 sqlFun | string | object note: this is autofield-ed, so if you can use a field name for it
expr2 sqlFun | object
Source:
Returns:
Type
sqlFun

(inner) isIn(expr1, list) → {sqlFun}

checks if expr1 is in the array list
Parameters:
Name Type Description
expr1 sqlFun | string | object note: this is autofield-ed, so if you can use a field name for it
list Array.<(sqlFun|object)> Array or function that evaluates into an array
Source:
Returns:
Type
sqlFun

(inner) isNotIn(expr1, list) → {sqlFun}

checks if expr1 is not in the array list
Parameters:
Name Type Description
expr1 sqlFun | string | object note: this is autofield-ed, so if you can use a field name for it
list Array.<sqlFun> | Array.<object> {Array} Array or function that evaluates into an array
Source:
Returns:
Type
sqlFun

(inner) isNotNull(expr1) → {sqlFun}

Check if an expression does not evaluate to null
Parameters:
Name Type Description
expr1 sqlFun | string | object
Source:
Returns:
f where f(expr) = true if expr does not evaluate to null f.toSql() = something like '(EXPR is not null)' where EXPR is the sql representation of the given expr
Type
sqlFun

(inner) isNull(expr1) → {sqlFun}

Check if an expression evaluates to null
Parameters:
Name Type Description
expr1 sqlFun | string | object
Source:
Returns:
f where f(expr) = true if expr evaluates to null f.toSql() = something like '(EXPR is null)' where EXPR is the sql representation of the given expr
Type
sqlFun

(inner) isNullOrEq(expr1, expr2) → {sqlFun}

checks if expr1 is null or equal to expr2
Parameters:
Name Type Description
expr1 sqlFun | string | object note: this is autofield-ed, so if you can use a field name for it
expr2 sqlFun | object
Source:
Returns:
Type
sqlFun

(inner) isNullOrGe(expr1, expr2) → {sqlFun}

checks if expr1 is null or greater than or equal to expr2
Parameters:
Name Type Description
expr1 note: this is autofield-ed, so if you can use a field name for it
expr2
Source:
Returns:
Type
sqlFun

(inner) isNullOrGt(expr1, expr2) → {sqlFun}

checks if expr1 is null or greater than expr2
Parameters:
Name Type Description
expr1 sqlFun | string | object note: this is autofield-ed, so if you can use a field name for it
expr2 sqlFun | object
Source:
Returns:
Type
sqlFun

(inner) isNullOrLe(expr1, expr2) → {sqlFun}

checks if expr1 is null or less than or equal to expr2
Parameters:
Name Type Description
expr1 sqlFun | string | object note: this is autofield-ed, so if you can use a field name for it
expr2 sqlFun | object
Source:
Returns:
Type
sqlFun

(inner) isNullOrLt(expr1, expr2) → {sqlFun}

checks if expr1 is null or less than expr2
Parameters:
Name Type Description
expr1 sqlFun | string | object note: this is autofield-ed, so if you can use a field name for it
expr2 sqlFun | object
Source:
Returns:
Type
sqlFun

(inner) le(expr1, expr2) → {sqlFun}

checks if expr1 evaluates less than or equal to from expr2
Parameters:
Name Type Description
expr1 sqlFun | string | object note: this is autofield-ed, so if you can use a field name for it
expr2 sqlFun | object
Source:
Returns:
Type
sqlFun

(inner) like(expr1, mask) → {sqlFun}

Checks if expr1 is (sql-like) mask, where mask can contain * and _ characters
Parameters:
Name Type Description
expr1 sqlFun | string | object expr1 note: this is autofield-ed, so if you can use a field name for it
mask sqlFun | object mask is a string or a function that evaluates into a string
Source:
Returns:
Type
sqlFun
Example
like('a','s%') compiles into (a like 's%')
       like(const('a'),'s%') compiles into ('a' like 's%')

(inner) list(values) → {sqlFun}

returns an array list from the parameters if all the parameters are legal. Oterwise it returns undefined or null.
Parameters:
Name Type Description
values Array.<sqlFun> | Array.<object>
Source:
Returns:
Type
sqlFun

(inner) lt(expr1, expr2) → {sqlFun}

checks if expr1 evaluates less than from expr2
Parameters:
Name Type Description
expr1 sqlFun | string | object note: this is autofield-ed, so if you can use a field name for it
expr2 sqlFun | object
Source:
Returns:
Type
sqlFun

(inner) max(expr1) → {sqlFun}

Evaluates the maximum value of an expression in a table. If any undefined is found, return undefined. Null are skipped. If all is null return null
Parameters:
Name Type Description
expr1 sqlFun | string | object
Source:
Returns:
Type
sqlFun

(inner) mcmp(keys, values, aliasopt) → {sqlFun}

Compares a set of keys of an object with an array of values or with fields of another object values can be an array or an object
Parameters:
Name Type Attributes Description
keys Array.<string> | Array.<object>
values Array.<sqlFun> | Array.<object> | object
alias string <optional>
Source:
Returns:
f(r) = true if : case values is an array: r[keys[i]] = values[i] for each i=0..keys.length-1 case values is an object: r[keys[i]] = values[keys[i]] for each i=0..keys.length-1
Type
sqlFun

(inner) mcmpEq(example, aliasopt) → {sqlFun}

Compares a set of keys of an object with an array of values or with fields of another object
Parameters:
Name Type Attributes Description
example object
alias string <optional>
Source:
Returns:
f(r) = true if for each non empty field of r: case field is null : field is null otherwise: r[field] = example[field]
Type
sqlFun

(inner) mcmpLike(example, aliasopt) → {sqlFun}

Compares a set of keys of an object with an array of values or with fields of another object
Parameters:
Name Type Attributes Description
example object
alias string <optional>
eventually table alias to use in conjunction with example field names
Source:
Returns:
f(r) = true if for each non empty field of r: case field is a string containing a %: field LIKE example[field] otherwise: field = example[field]
Type
sqlFun

(inner) min(expr1) → {sqlFun}

Evaluates the minimum value of an expression in a table. If any undefined is found, return undefined. Null are skipped. If all is null return null
Parameters:
Name Type Description
expr1 sqlFun | string | object
Source:
Returns:
Type
sqlFun

(inner) minus(expr1) → {sqlFun}

Parameters:
Name Type Description
expr1 sqlFun | string | object
Source:
Returns:
f where f(r) = - r. r should evaluate into a number
Type
sqlFun

(inner) modulus(expr1, expr2) → {sqlFun}

returns a functions that does the modulus
Parameters:
Name Type Description
expr1 sqlFun | string | object
expr2 sqlFun | object
Source:
Returns:
Type
sqlFun

(inner) mul(values) → {sqlFun}

returns a functions that evaluates the multiply of a list or array of values If some operand is 0, returns the always 0 function
Parameters:
Name Type Description
values Array.<sqlFun> | Array.<object>
Source:
Returns:
Type
sqlFun

(inner) ne(expr1, expr2) → {sqlFun}

checks if expr1 evaluates different from expr2
Parameters:
Name Type Description
expr1 sqlFun | string | object note: this is autofield-ed, so if you can use a field name for it
expr2 sqlFun | object
Source:
Returns:
Type
sqlFun

(inner) not(expr1) → {sqlFun}

Parameters:
Name Type Description
expr1 sqlFun | string | object
Source:
Returns:
f where f(r) = not r. r should evaluate into a boolean
Type
sqlFun

(inner) or(arr) → {sqlFun}

checks if at least one of supplied expression evaluates to a truthy value
Parameters:
Name Type Description
arr Array.<sqlFun> | Array.<object> array or list of expression
Source:
Returns:
Type
sqlFun

(inner) sub(expr1, expr2) → {sqlFun}

returns a functions that does a subtraction
Parameters:
Name Type Description
expr1 sqlFun | string | object
expr2 sqlFun | object
Source:
Returns:
Type
sqlFun

(inner) substring(expr1, start, len) → {sqlFun}

Parameters:
Name Type Description
expr1 sqlFun | string | object
start sqlFun | object
len sqlFun | object
Source:
Returns:
Type
sqlFun

(inner) sum(expr1) → {sqlFun}

Evaluates the sum of an array of element given at run time
Parameters:
Name Type Description
expr1 sqlFun | string | object
Source:
Returns:
Type
sqlFun

(inner) testMask(expr1, mask, val) → {sqlFun}

check if expr1 & mask === val & mask
Parameters:
Name Type Description
expr1 sqlFun | string note: this is autofield-ed, so if you can use a field name for it
mask sqlFun | object
val sqlFun | object
Source:
Returns:
Type
sqlFun