QueryBuilder

State

State(Driver, driver)

Parameters

  • Driver :

    The driver object for the database in use

  • driver :

_appendMap(conjunction, string, type)

Append a clause to the query map

Parameters

Returns

void

helpers(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
.upperCaseFirst(str)

Make the first letter of the string uppercase

upperCaseFirst(str)

Make the first letter of the string uppercase

Parameters

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

constructor(Driver, driver)

Parameters

  • Driver :

    The driver object for the database in use

  • driver :

Returns

void

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

filterMatches(array)

Filter matched patterns

Parameters

Returns

Array or

from(tableName)

Specify the database table to select from

Parameters

  • String tableName :

    The table to use for the current query

Returns

QueryBuilder

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

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

groupBy(field)

Group the results by the selected field(s)

Parameters

Returns

QueryBuilder

groupEnd

Ends a logical grouping started with one of the groupStart methods

Returns

QueryBuilder

groupStart

Adds an open paren to the current query for logical grouping

Returns

QueryBuilder

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

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

QueryBuilder

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

QueryBuilder

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

QueryBuilder

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

QueryBuilder

orGroupStart

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

Returns

QueryBuilder

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

QueryBuilder

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

QueryBuilder

orNotGroupStart

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

Returns

QueryBuilder

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

QueryBuilder

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

QueryBuilder

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

QueryBuilder

orWhereIsNotNull(field)

Field is not null prefixed with 'OR'

Parameters

Returns

QueryBuilder

orWhereIsNull(field)

Field is null prefixed with 'OR'

Parameters

Returns

QueryBuilder

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

QueryBuilder

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

QueryBuilder

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

  • Driver driver :
  • State state :

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

QueryBuilder

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

QueryBuilder

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

QueryBuilder

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

QueryBuilder

whereIsNotNull(field)

Specify that a field IS NOT NULL

Parameters

Returns

QueryBuilder

whereIsNull(field)

Select a field that is Null

Parameters

  • String field :

    The name of the field that has a NULL value

Returns

QueryBuilder

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

QueryBuilder