API Docs for: 1.0.1
Show:

jsDataQuery Class

Module: jsDataQuery

Compare function provider to help building conditions that can be applyed both to collections, using the returned function as a filter, or to a database, using the toSql() method

Methods

add

(
  • values
)
SqlFun

returns a functions that evaluates the sum of a list or array of values given when it is CREATED

Parameters:

Returns:

SqlFun:

and

(
  • arr
)
SqlFun

checks if all supplied expression evaluate to truthy values

Parameters:

  • arr SqlFun | Object[]

    array or list of expression

Returns:

SqlFun:

as

(
  • fieldName
)
SqlFun

Establish the output name for an expression

Parameters:

Returns:

SqlFun:

autofield

(
  • p
)
SqlFun private

Parameters:

Returns:

SqlFun:

between

(
  • expr1
  • min
  • max
)
SqlFun

Check if expr1 evaluates between min and max

Parameters:

  • 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

Returns:

SqlFun:

bitClear

(
  • expression
  • nbit
)
SqlFun

Check if the nth bit of expression is not set

Parameters:

  • expression SqlFun | String

    note: this is autofield-ed, so if you can use a field name for it

  • nbit SqlFun | Object

Returns:

SqlFun:

bitSet

(
  • expression
  • nbit
)
SqlFun

Check if the nth bit of expression is set

Parameters:

  • expression SqlFun | String | Object

    note: this is autofield-ed, so if you can use a field name for it

  • nbit SqlFun | Object

Returns:

SqlFun:

bitwiseAnd

(
  • arr
)
SqlFun

Parameters:

  • arr SqlFun | Object[]

    array or list of expression

Returns:

SqlFun:

bitwiseNot

(
  • }
)
SqlFun

Parameters:

  • } SqlFun | String | Object

    expression note: this is autofield-ed, so if you can use a field name for it

Returns:

SqlFun:

bitwiseOr

(
  • arr
)
SqlFun

Parameters:

  • arr SqlFun | Object[]

    array or list of expression

Returns:

SqlFun:

bitwiseXor

(
  • arr
)
SqlFun

Parameters:

  • arr SqlFun | Object[]

    array or list of expression

Returns:

SqlFun:

calc

(
  • expr
  • r
  • context
)
Object | String | Null | Undefined

Evaluates an expression in a given context

Parameters:

Returns:

Object | String | Null | Undefined:

expr evaluated in the context r undefined are returned as null constant

concat

(
  • values
)
SqlFun

returns a functions that evaluates the concatenation of a list or array of strings given when it is CREATED

Parameters:

Returns:

SqlFun:

constant

(
  • value
)
SqlFun

Defines a constant function. The toSql method invokes the formatter.quote function

Parameters:

Returns:

SqlFun:

f such that f()= k, f.toSql()= formatter.quote(k)

context

(
  • environmentVariable
)
SqlFun

Transforms a generic function into a sqlFun, returning a similar function with some additional methods

Parameters:

  • environmentVariable String

    Environment variable name

Returns:

SqlFun:

Example:

if environment = {a:1, b:2} and environmentFunction = function (env){return env.a} context(environmentFunction) applied to environment will return 1

convertToInt

(
  • expr1
)
SqlFun

Converts a generic expression into an integer

Parameters:

Returns:

SqlFun:

convertToString

(
  • expr1
  • maxLen
)
SqlFun

Converts a generic expression into a string

Parameters:

  • expr1 SqlFun | String | Object
  • maxLen Int

    maximum string len

Returns:

SqlFun:

distinctVal

(
  • arr
  • fieldname
)
Object[] | Undefined

Finds distinct values of a field

Parameters:

Returns:

Object[] | Undefined:

distinctVal

(
  • exprList
)
SqlFun

Finds distinct values of a list of fields

Parameters:

  • exprList (sqlFun | Object)

Returns:

SqlFun:

div

(
  • expr1
  • expr2
)
SqlFun

returns a functions that does a division

Parameters:

Returns:

SqlFun:

eq

(
  • expr1
  • expr2
)
SqlFun

checks if expr1 evaluates equal to expr2

Parameters:

  • expr1 SqlFun | String | Object

    note: this is autofield-ed, so if you can use a field name for it

  • expr2 SqlFun | Object

Returns:

SqlFun:

field

(
  • fieldName
  • [tableName]
)
SqlFun

Gets a field from an object. This is a very important function to distinguish between generic strings and field names.

Parameters:

Returns:

SqlFun:

f such that f(r) = r[fieldName] f.toSql() = 'fieldName' or 'tableName.fieldName' where tableName is specified

ge

(
  • expr1
  • expr2
)
SqlFun

checks if expr1 evaluates greater than or equal to expr2

Parameters:

  • expr1 SqlFun | String | Object

    note: this is autofield-ed, so if you can use a field name for it

  • expr2 SqlFun | Object

Returns:

SqlFun:

gt

(
  • expr1
  • expr2
)
SqlFun

checks if expr1 evaluates greater than expr2

Parameters:

  • expr1 SqlFun | String | Object

    note: this is autofield-ed, so if you can use a field name for it

  • expr2 SqlFun | Object

Returns:

SqlFun:

isIn

(
  • expr1
  • list
)
SqlFun

checks if expr1 is in the array list

Parameters:

  • expr1 SqlFun | String | Object

    note: this is autofield-ed, so if you can use a field name for it

  • list (sqlFun | Object)

    Array or function that evaluates into an array

Returns:

SqlFun:

isNotIn

(
  • expr1
  • list
)
SqlFun

checks if expr1 is not in the array list

Parameters:

  • expr1 SqlFun | String | Object

    note: this is autofield-ed, so if you can use a field name for it

  • list SqlFun | Object[]

    {Array} Array or function that evaluates into an array

Returns:

SqlFun:

isNotNull

(
  • expr1
)
SqlFun

Check if an expression does not evaluate to null

Parameters:

Returns:

SqlFun:

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

isNull

(
  • expr1
)
SqlFun

Check if an expression evaluates to null

Parameters:

Returns:

SqlFun:

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

isNullOrEq

(
  • expr1
  • expr2
)
SqlFun

checks if expr1 is null or equal to expr2

Parameters:

  • expr1 SqlFun | String | Object

    note: this is autofield-ed, so if you can use a field name for it

  • expr2 SqlFun | Object

Returns:

SqlFun:

isNullOrGe

(
  • expr1
  • expr2
)
SqlFun

checks if expr1 is null or greater than or equal to expr2

Parameters:

  • expr1 Object

    note: this is autofield-ed, so if you can use a field name for it

  • expr2 Object

Returns:

SqlFun:

isNullOrGt

(
  • expr1
  • expr2
)
SqlFun

checks if expr1 is null or greater than expr2

Parameters:

  • expr1 SqlFun | String | Object

    note: this is autofield-ed, so if you can use a field name for it

  • expr2 SqlFun | Object

Returns:

SqlFun:

isNullOrLe

(
  • expr1
  • expr2
)
SqlFun

checks if expr1 is null or less than or equal to expr2

Parameters:

  • expr1 SqlFun | String | Object

    note: this is autofield-ed, so if you can use a field name for it

  • expr2 SqlFun | Object

Returns:

SqlFun:

isNullOrLt

(
  • expr1
  • expr2
)
SqlFun

checks if expr1 is null or less than expr2

Parameters:

  • expr1 SqlFun | String | Object

    note: this is autofield-ed, so if you can use a field name for it

  • expr2 SqlFun | Object

Returns:

SqlFun:

isNullOrUndefined

(
  • o
)
Boolean

Check if an object is the null or undefined constant

Parameters:

  • o SqlFun | Undefined | Null | Object

Returns:

Boolean:

true if o is null or undefined

le

(
  • expr1
  • expr2
)
SqlFun

checks if expr1 evaluates less than or equal to from expr2

Parameters:

  • expr1 SqlFun | String | Object

    note: this is autofield-ed, so if you can use a field name for it

  • expr2 SqlFun | Object

Returns:

SqlFun:

like

(
  • expr1
  • mask
)
SqlFun

Checks if expr1 is (sql-like) mask, where mask can contain * and _ characters

Parameters:

  • 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

Returns:

SqlFun:

Example:

like('a','s%') compiles into (a like 's%') like(const('a'),'s%') compiles into ('a' like 's%')

list

(
  • values
)
SqlFun

returns an array list from the parameters if all the parameters are legal. Oterwise it returns undefined or null.

Parameters:

Returns:

SqlFun:

lt

(
  • expr1
  • expr2
)
SqlFun

checks if expr1 evaluates less than from expr2

Parameters:

  • expr1 SqlFun | String | Object

    note: this is autofield-ed, so if you can use a field name for it

  • expr2 SqlFun | Object

Returns:

SqlFun:

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:

Returns:

SqlFun:

mcmp

(
  • keys
  • values
  • [alias]
)
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:

Returns:

SqlFun:

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

mcmpEq

(
  • example
  • [alias]
)
SqlFun

Compares a set of keys of an object with an array of values or with fields of another object

Parameters:

Returns:

SqlFun:

f(r) = true if for each non empty field of r: case field is null : field is null otherwise: r[field] = example[field]

mcmpLike

(
  • example
  • [alias]
)
SqlFun

Compares a set of keys of an object with an array of values or with fields of another object

Parameters:

  • example Object
  • [alias] String optional

    eventually table alias to use in conjunction with example field names

Returns:

SqlFun:

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]

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:

Returns:

SqlFun:

minus

(
  • expr1
)
SqlFun

Parameters:

Returns:

SqlFun:

f where f(r) = - r. r should evaluate into a number

modulus

(
  • expr1
  • expr2
)
SqlFun

returns a functions that does the modulus

Parameters:

Returns:

SqlFun:

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:

Returns:

SqlFun:

ne

(
  • expr1
  • expr2
)
SqlFun

checks if expr1 evaluates different from expr2

Parameters:

  • expr1 SqlFun | String | Object

    note: this is autofield-ed, so if you can use a field name for it

  • expr2 SqlFun | Object

Returns:

SqlFun:

not

(
  • expr1
)
SqlFun

Parameters:

Returns:

SqlFun:

f where f(r) = not r. r should evaluate into a boolean

or

(
  • arr
)
SqlFun

checks if at least one of supplied expression evaluates to a truthy value

Parameters:

  • arr SqlFun | Object[]

    array or list of expression

Returns:

SqlFun:

sub

(
  • expr1
  • expr2
)
SqlFun

returns a functions that does a subtraction

Parameters:

Returns:

SqlFun:

substring

(
  • expr1
  • start
  • len
)
SqlFun

Parameters:

Returns:

SqlFun:

sum

(
  • expr1
)
SqlFun

Evaluates the sum of an array of element given at run time

Parameters:

Returns:

SqlFun:

testMask

(
  • expr1
  • mask
  • val
)
SqlFun

check if expr1 & mask === val & mask

Parameters:

  • expr1 SqlFun | String

    note: this is autofield-ed, so if you can use a field name for it

  • mask SqlFun | Object
  • val SqlFun | Object

Returns:

SqlFun:

toSqlFun

(
  • f
  • toSql
)
SqlFun private

Parameters:

Returns:

SqlFun: