Module: query-builder

query-builder

Members

<private, inner> state

Variables controlling the sql building

Source:

Methods

delete(table, where, callback)

Run the generated delete query

Parameters:
Name Type Argument Description
table String

The table to insert into

where Object <optional>

Where clause for delete statement

callback function

Callback for handling response from the database

Source:
Returns:

void

from(tableName)

Specify the database table to select from

Parameters:
Name Type Description
tableName String

The table to use for the current query

Source:
Returns:

this

get(table, limit, offset, callback)

Get the results of the compiled query

Parameters:
Name Type Argument Description
table String <optional>

The table to select from

limit Number <optional>

A limit for the query

offset Number <optional>

An offset for the query

callback function

A callback for receiving the result

Source:
Returns:

void

getCompiledDelete(table, reset) → {String}

Return generated delete query SQL

Parameters:
Name Type Argument Default Description
table String

the name of the table to delete from

reset Boolean <optional>
true

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

Source:
Returns:
Type
String

getCompiledInsert(table, reset) → {String}

Return generated insert query SQL

Parameters:
Name Type Argument Default Description
table String

the name of the table to insert into

reset Boolean <optional>
true

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

Source:
Returns:
Type
String

getCompiledSelect(table, reset)

Return generated select query SQL

Parameters:
Name Type Argument Default Description
table String <optional>

the name of the table to retrieve from

reset Boolean <optional>
true

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

Source:
Returns:

String

getCompiledUpdate(table, reset) → {String}

Return generated update query SQL

Parameters:
Name Type Argument Default Description
table String

the name of the table to update

reset Boolean <optional>
true

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

Source:
Returns:
Type
String

<private> getState() → {Object}

Returns the current class state for testing or other purposes

Source:
Returns:
Type
Object

groupBy(field)

Group the results by the selected field(s)

Parameters:
Name Type Description
field String | Array
Source:
Returns:

this

groupEnd()

Ends a logical grouping started with one of the groupStart methods

Source:
Returns:

this

groupStart()

Adds an open paren to the current query for logical grouping

Source:
Returns:

this

having(key, val)

Add a 'having' clause

Parameters:
Name Type Argument Description
key String | Object

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

val String | Number <optional>

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

Source:
Returns:

this

insert(table, data, callback)

Run the generated insert query

Parameters:
Name Type Argument Description
table String

The table to insert into

data Object <optional>

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

callback function

Callback for handling response from the database

Source:
Returns:

void

insertBatch(table, data, callback)

Insert multiple sets of rows at a time

Parameters:
Name Type Description
table String

The table to insert into

data Array

The array of objects containing data rows to insert

callback function

Callback for handling database response

Source:
Returns:

void

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

join(table, cond, type)

Add a join clause to the query

Parameters:
Name Type Argument Default Description
table String

The table you are joining

cond String

The join condition.

type String <optional>
'inner'

The type of join, which defaults to inner

Source:
Returns:

this

like(field, val, pos)

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

Parameters:
Name Type Argument Default Description
field String

The name of the field to compare to

val String

The value to compare to

pos String <optional>
both

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

Source:
Returns:

this

limit(limit, offset)

Put a limit on the query

Parameters:
Name Type Argument Description
limit Number

The maximum number of rows to fetch

offset Number <optional>

The row number to start from

Source:
Returns:

this

notLike(field, val, pos)

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

Parameters:
Name Type Argument Default Description
field String

The name of the field to compare to

val String

The value to compare to

pos String <optional>
both

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

Source:
Returns:

this

orderBy(field, type)

Order the results by the selected field(s)

Parameters:
Name Type Argument Default Description
field String

The field(s) to order by

type String <optional>
'ASC'

The order direction, ASC or DESC

Source:
Returns:

this

orGroupStart()

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

Source:
Returns:

this

orHaving(key, val)

Add an 'or having' clause

Parameters:
Name Type Argument Description
key String | Object

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

val String | Number <optional>

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

Source:
Returns:

this

orLike(field, val, pos)

Add an 'or like' clause to the query

Parameters:
Name Type Argument Default Description
field String

The name of the field to compare to

val String

The value to compare to

pos String <optional>
both

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

Source:
Returns:

this

orNotGroupStart()

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

Source:
Returns:

this

orNotLike(field, val, pos)

Add an 'or not like' clause to the query

Parameters:
Name Type Argument Default Description
field String

The name of the field to compare to

val String

The value to compare to

pos String <optional>
both

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

Source:
Returns:

this

orWhere(key, val)

Set a 'or where' clause

Parameters:
Name Type Argument Description
key String | Object

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

val String | Number <optional>

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

Source:
Returns:

this

orWhereIn(key, val)

Set a 'or where in' clause

Parameters:
Name Type Description
key String

the field to search

val Array

the array of items to search in

Source:
Returns:

this

orWhereNotIn(key, val)

Set a 'or where not in' clause

Parameters:
Name Type Description
key String

the field to search

val Array

the array of items to search in

Source:
Returns:

this

select(fields)

Specify rows to select in the query

Parameters:
Name Type Description
fields String | Array

The fields to select from the current table

Source:
Returns:

this

set(key, val)

Set values for insertion or updating

Parameters:
Name Type Argument Description
key String | Object

The key or object to use

val String <optional>

The value if using a scalar key

Source:
Returns:

this

update(table, data, callback)

Run the generated update query

Parameters:
Name Type Argument Description
table String

The table to insert into

data Object <optional>

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

callback function

Callback for handling response from the database

Source:
Returns:

void

where(key, val)

Set a 'where' clause

Parameters:
Name Type Argument Description
key String | Object

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

val String | Number <optional>

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

Source:
Returns:

this

whereIn(key, val)

Set a 'where in' clause

Parameters:
Name Type Description
key String

the field to search

val Array

the array of items to search in

Source:
Returns:

this

whereNotIn(key, val)

Set a 'where not in' clause

Parameters:
Name Type Description
key String

the field to search

val Array

the array of items to search in

Source:
Returns:

this

DocStrap Copyright © 2012-2014 The contributors to the JSDoc3 and DocStrap projects.
Documentation generated by JSDoc 3.3.0-alpha9 on Fri Oct 31st 2014 using the DocStrap template.