NodeQuery

QueryParser(Driver, driver)

Parameters

  • Driver :

    The driver object for the database in use

  • driver :

State

h(o)

Determine whether a variable is of the type specified in the function name, eg isNumber

Types available are Null, Undefined, Object, Array, String, Number, Boolean, Function, RegExp, NaN and Infinite

Parameters

  • mixed o :

Returns

Boolean

Static members

.arrayPluck(arr, key)

Get a list of values with a common key from an array of objects

arrayPluck(arr, key)

Get a list of values with a common key from an array of objects

Parameters

  • Array arr :

    The array of objects to search

  • String key :

    The key of the object to get

Returns

Array
.isScalar(obj)

Determine whether an object is scalar

isScalar(obj)

Determine whether an object is scalar

Parameters

  • mixed obj :

Returns

bool
.regexInArray(arr, pattern)

Determine if a value matching the passed regular expression is in the passed array

regexInArray(arr, pattern)

Determine if a value matching the passed regular expression is in the passed array

Parameters

  • Array arr :

    The array to search

  • RegExp pattern :

    The pattern to match

Returns

Boolean :

If an array item matches the pattern

.stringTrim(str)

Wrap String.prototype.trim in a way that is easily mappable

stringTrim(str)

Wrap String.prototype.trim in a way that is easily mappable

Parameters

  • String str :

    The string to trim

Returns

String :

The trimmed string

.type(o)

Get the type of the variable passed

type(o)

Get the type of the variable passed

Parameters

  • mixed o :

Returns

String

h(str)

Parameters

  • str :

Static members

.arrayPluck(arr, key)

Get a list of values with a common key from an array of objects

arrayPluck(arr, key)

Get a list of values with a common key from an array of objects

Parameters

  • Array arr :

    The array of objects to search

  • String key :

    The key of the object to get

Returns

Array
.isScalar(obj)

Determine whether an object is scalar

isScalar(obj)

Determine whether an object is scalar

Parameters

  • mixed obj :

Returns

bool
.regexInArray(arr, pattern)

Determine if a value matching the passed regular expression is in the passed array

regexInArray(arr, pattern)

Determine if a value matching the passed regular expression is in the passed array

Parameters

  • Array arr :

    The array to search

  • RegExp pattern :

    The pattern to match

Returns

Boolean :

If an array item matches the pattern

.stringTrim(str)

Wrap String.prototype.trim in a way that is easily mappable

stringTrim(str)

Wrap String.prototype.trim in a way that is easily mappable

Parameters

  • String str :

    The string to trim

Returns

String :

The trimmed string

.type(o)

Get the type of the variable passed

type(o)

Get the type of the variable passed

Parameters

  • mixed o :

Returns

String

compileJoin(condition)

Return the output of the parsing of the join condition

Parameters

  • String condition :

    The join condition to evalate

Returns

String :

The parsed/escaped join condition

delete(table, [where], callback)

Run the generated delete query

Parameters

  • String table :

    The table to insert into

  • [Object] where :

    Where clause for delete statement

  • Function callback :

    Callback for handling response from the database

Returns

:

void

end

Closes the database connection for the current adapter

Returns

:

void

from(tableName)

Specify the database table to select from

Parameters

  • String tableName :

    The table to use for the current query

Returns

:

this

get([table], [limit], [offset], callback)

Get the results of the compiled query

Parameters

  • [String] table :

    The table to select from

  • [Number] limit :

    A limit for the query

  • [Number] offset :

    An offset for the query

  • Function callback :

    A callback for receiving the result

Returns

:

void

getArgs

getCompiledDelete(table, [reset])

Return generated delete query SQL

Parameters

  • String table :

    the name of the table to delete from

  • [Boolean] reset (default true) :

    Whether to reset the query builder so another query can be built

Returns

String

getCompiledInsert(table, [reset])

Return generated insert query SQL

Parameters

  • String table :

    the name of the table to insert into

  • [Boolean] reset (default true) :

    Whether to reset the query builder so another query can be built

Returns

String

getCompiledSelect([table], [reset])

Return generated select query SQL

Parameters

  • [String] table :

    the name of the table to retrieve from

  • [Boolean] reset (default true) :

    Whether to reset the query builder so another query can be built

Returns

:

String

getCompiledUpdate(table, [reset])

Return generated update query SQL

Parameters

  • String table :

    the name of the table to update

  • [Boolean] reset (default true) :

    Whether to reset the query builder so another query can be built

Returns

String

getQuery

Return an existing query builder instance

Returns

queryBuilder

groupBy(field)

Group the results by the selected field(s)

Parameters

Returns

:

this

groupEnd

Ends a logical grouping started with one of the groupStart methods

Returns

:

this

groupStart

Adds an open paren to the current query for logical grouping

Returns

:

this

hasOperator(string)

Check if the string contains an operator, and if so, return the operator(s). If there are no matches, return null

Parameters

  • String string :

    the string to check

Returns

Array or

having(key, [val])

Add a 'having' clause

Parameters

  • String or Object key :

    The name of the field and the comparision operator, or an object

  • [String or Number] val :

    The value to compare if the value of key is a string

Returns

:

this

helpers(str)

Parameters

  • str :

init(drivername, driverType, connObject, [connLib])

Create a query builder object

Parameters

  • String drivername :

    The name of the database type, eg. mysql or pg

  • driverType :
  • Object connObject :

    A connection object from the database library you are connecting with

  • [String] connLib :

    The name of the db connection library you are using, eg. mysql or mysql2. Optional if the same as drivername

Returns

queryBuilder

insert(table, [data], callback)

Run the generated insert query

Parameters

  • String table :

    The table to insert into

  • [Object] data :

    Data to insert, if not already added with the 'set' method

  • Function callback :

    Callback for handling response from the database

Returns

:

void

insertBatch(table, data, callback)

Insert multiple sets of rows at a time

Parameters

  • String table :

    The table to insert into

  • Array data :

    The array of objects containing data rows to insert

  • Function callback :

    Callback for handling database response

Returns

:

void

Examples

query.insertBatch('foo',[{id:1,val:'bar'},{id:2,val:'baz'}], callbackFunction);

join(table, cond, [type])

Add a join clause to the query

Parameters

  • String table :

    The table you are joining

  • String cond :

    The join condition.

  • [String] type (default 'inner') :

    The type of join, which defaults to inner

Returns

:

this

like(field, val, [pos])

Add a 'like/ and like' clause to the query

Parameters

  • String field :

    The name of the field to compare to

  • String val :

    The value to compare to

  • [String] pos (default both) :

    The placement of the wildcard character(s): before, after, or both

Returns

:

this

limit(limit, [offset])

Put a limit on the query

Parameters

  • Number limit :

    The maximum number of rows to fetch

  • [Number] offset :

    The row number to start from

Returns

:

this

notLike(field, val, [pos])

Add a 'not like/ and not like' clause to the query

Parameters

  • String field :

    The name of the field to compare to

  • String val :

    The value to compare to

  • [String] pos (default both) :

    The placement of the wildcard character(s): before, after, or both

Returns

:

this

orGroupStart

Adds an open paren to the current query for logical grouping, prefixed with 'OR'

Returns

:

this

orHaving(key, [val])

Add an 'or having' clause

Parameters

  • String or Object key :

    The name of the field and the comparision operator, or an object

  • [String or Number] val :

    The value to compare if the value of key is a string

Returns

:

this

orLike(field, val, [pos])

Add an 'or like' clause to the query

Parameters

  • String field :

    The name of the field to compare to

  • String val :

    The value to compare to

  • [String] pos (default both) :

    The placement of the wildcard character(s): before, after, or both

Returns

:

this

orNotGroupStart

Adds an open paren to the current query for logical grouping, prefixed with 'OR NOT'

Returns

:

this

orNotLike(field, val, [pos])

Add an 'or not like' clause to the query

Parameters

  • String field :

    The name of the field to compare to

  • String val :

    The value to compare to

  • [String] pos (default both) :

    The placement of the wildcard character(s): before, after, or both

Returns

:

this

orWhere(key, [val])

Set a 'or where' clause

Parameters

  • String or Object key :

    The name of the field and the comparision operator, or an object

  • [String or Number] val :

    The value to compare if the value of key is a string

Returns

:

this

orWhereIn(key, val)

Set a 'or where in' clause

Parameters

  • String key :

    the field to search

  • Array val :

    the array of items to search in

Returns

:

this

orWhereIsNotNull(field)

Field is not null prefixed with 'OR'

Parameters

Returns

:

this

orWhereIsNull(field)

Field is null prefixed with 'OR'

Parameters

Returns

:

this

orWhereNotIn(key, val)

Set a 'or where not in' clause

Parameters

  • String key :

    the field to search

  • Array val :

    the array of items to search in

Returns

:

this

orderBy(field, [type])

Order the results by the selected field(s)

Parameters

  • String field :

    The field(s) to order by

  • [String] type (default 'ASC') :

    The order direction, ASC or DESC

Returns

:

this

parseJoin(sql)

Tokenize the sql into parts for additional processing

Parameters

Returns

Object

parseWhere(driver, state)

Parse a where clause to separate functions from values

Parameters

Returns

String :

The parsed/escaped where condition

resetQuery

Reset the object state for a new query

Returns

:

void

select(fields)

Specify rows to select in the query

Parameters

  • String or Array fields :

    The fields to select from the current table

Returns

:

this

set(key, [val])

Set values for insertion or updating

Parameters

  • String or Object key :

    The key or object to use

  • [String] val :

    The value if using a scalar key

Returns

:

this

update(table, [data], callback)

Run the generated update query

Parameters

  • String table :

    The table to insert into

  • [Object] data :

    Data to insert, if not already added with the 'set' method

  • Function callback :

    Callback for handling response from the database

Returns

:

void

where(key, [val])

Set a 'where' clause

Parameters

  • String or Object key :

    The name of the field and the comparision operator, or an object

  • [String or Number] val :

    The value to compare if the value of key is a string

Returns

:

this

whereIn(key, val)

Set a 'where in' clause

Parameters

  • String key :

    the field to search

  • Array val :

    the array of items to search in

Returns

:

this

whereIsNotNull(field)

Specify that a field IS NOT NULL

Parameters

Returns

:

this

whereIsNull(field)

Select a field that is Null

Parameters

  • String field :

    The name of the field that has a NULL value

Returns

:

this

whereNotIn(key, val)

Set a 'where not in' clause

Parameters

  • String key :

    the field to search

  • Array val :

    the array of items to search in

Returns

:

this