node-query/API.md

583 lines
22 KiB
Markdown
Raw Normal View History

<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
2018-02-12 14:58:50 -05:00
### Table of Contents
- [NodeQuery](#nodequery)
- [getQuery](#getquery)
- [QueryBuilder](#querybuilder)
- [queryFile](#queryfile)
- [query](#query)
- [resetQuery](#resetquery)
- [truncate](#truncate)
- [end](#end)
- [select](#select)
- [from](#from)
- [like](#like)
- [notLike](#notlike)
- [orLike](#orlike)
- [orNotLike](#ornotlike)
- [having](#having)
- [orHaving](#orhaving)
- [where](#where)
- [orWhere](#orwhere)
- [whereIsNull](#whereisnull)
- [whereIsNotNull](#whereisnotnull)
- [orWhereIsNull](#orwhereisnull)
- [orWhereIsNotNull](#orwhereisnotnull)
- [whereIn](#wherein)
- [orWhereIn](#orwherein)
- [whereNotIn](#wherenotin)
- [orWhereNotIn](#orwherenotin)
- [set](#set)
- [join](#join)
- [groupBy](#groupby)
- [orderBy](#orderby)
- [limit](#limit)
- [groupStart](#groupstart)
- [orGroupStart](#orgroupstart)
- [orNotGroupStart](#ornotgroupstart)
- [groupEnd](#groupend)
- [get](#get)
- [insert](#insert)
- [insertBatch](#insertbatch)
- [update](#update)
- [updateBatch](#updatebatch)
- [delete](#delete)
- [getCompiledSelect](#getcompiledselect)
- [getCompiledInsert](#getcompiledinsert)
- [getCompiledUpdate](#getcompiledupdate)
- [getCompiledDelete](#getcompileddelete)
- [Result](#result)
- [rowCount](#rowcount)
- [columnCount](#columncount)
## NodeQuery
2016-01-26 20:23:52 -05:00
Class for connection management
**Parameters**
2018-02-12 14:58:50 -05:00
- `config` **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** connection parameters
2018-02-12 14:58:50 -05:00
### getQuery
2016-01-26 20:23:52 -05:00
Return an existing query builder instance
2016-07-20 16:33:09 -04:00
Returns **[QueryBuilder](#querybuilder)** The Query Builder object
2016-01-26 20:23:52 -05:00
2018-02-12 14:58:50 -05:00
## QueryBuilder
2016-01-26 20:23:52 -05:00
2016-07-20 16:33:09 -04:00
**Extends QueryBuilderBase**
2016-01-26 20:23:52 -05:00
Main object that builds SQL queries.
**Parameters**
- `Driver` **Driver** The syntax driver for the database
- `Adapter` **Adapter** The database module adapter for running queries
2018-02-12 14:58:50 -05:00
### queryFile
Run a set of queries from a file
**Parameters**
- `file` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** The path to the sql file
- `separator` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** The character separating each query (optional, default `';'`)
Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)** The result of all the queries
### query
2016-01-26 20:23:52 -05:00
2016-07-20 16:33:09 -04:00
Run an arbitrary sql query. Run as a prepared statement.
2016-01-26 20:23:52 -05:00
**Parameters**
2018-02-12 14:58:50 -05:00
- `sql` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** The sql to execute
- `params` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)?** The query parameters
2016-01-26 20:23:52 -05:00
2018-02-12 14:58:50 -05:00
Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)** Promise with result of query
2016-07-20 16:33:09 -04:00
2018-02-12 14:58:50 -05:00
### resetQuery
2016-07-20 16:33:09 -04:00
Reset the object state for a new query
Returns **void**
2018-02-12 14:58:50 -05:00
### truncate
2016-07-20 16:33:09 -04:00
Empties the selected database table
**Parameters**
2018-02-12 14:58:50 -05:00
- `table` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** the name of the table to truncate
2016-07-20 16:33:09 -04:00
2018-02-12 14:58:50 -05:00
Returns **(void | [Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise))** Returns a promise if no callback is supplied
2016-01-26 20:23:52 -05:00
2018-02-12 14:58:50 -05:00
### end
2016-01-26 20:23:52 -05:00
Closes the database connection for the current adapter
Returns **void**
2018-02-12 14:58:50 -05:00
### select
2016-01-26 20:23:52 -05:00
2016-07-20 16:33:09 -04:00
Specify rows to select in the query
2016-01-26 20:23:52 -05:00
**Parameters**
2018-02-12 14:58:50 -05:00
- `fields` **([String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) \| [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array))** The fields to select from the current table
2016-01-26 20:23:52 -05:00
**Examples**
```javascript
2016-07-20 16:33:09 -04:00
query.select('foo, bar'); // Select multiple fields with a string
2016-01-26 20:23:52 -05:00
```
```javascript
2016-07-20 16:33:09 -04:00
query.select(['foo', 'bar']); // Select multiple fileds with an array
2016-01-26 20:23:52 -05:00
```
2016-07-20 16:33:09 -04:00
Returns **[QueryBuilder](#querybuilder)** The Query Builder object, for chaining
2016-01-26 20:23:52 -05:00
2018-02-12 14:58:50 -05:00
### from
2016-01-26 20:23:52 -05:00
2016-07-20 16:33:09 -04:00
Specify the database table to select from
2016-01-26 20:23:52 -05:00
**Parameters**
2018-02-12 14:58:50 -05:00
- `tableName` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** The table to use for the current query
2016-01-26 20:23:52 -05:00
**Examples**
```javascript
2016-07-20 16:33:09 -04:00
query.from('tableName');
2016-01-26 20:23:52 -05:00
```
```javascript
2016-07-20 16:33:09 -04:00
query.from('tableName t'); // Select the table with an alias
2016-01-26 20:23:52 -05:00
```
2016-07-20 16:33:09 -04:00
Returns **[QueryBuilder](#querybuilder)** The Query Builder object, for chaining
2016-01-26 20:23:52 -05:00
2018-02-12 14:58:50 -05:00
### like
2016-01-26 20:23:52 -05:00
2016-07-20 16:33:09 -04:00
Add a 'like/ and like' clause to the query
2016-01-26 20:23:52 -05:00
**Parameters**
2018-02-12 14:58:50 -05:00
- `field` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** The name of the field to compare to
- `val` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** The value to compare to
- `pos` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** The placement of the wildcard character(s): before, after, or both (optional, default `both`)
2016-01-26 20:23:52 -05:00
2016-07-20 16:33:09 -04:00
Returns **[QueryBuilder](#querybuilder)** The Query Builder object, for chaining
2016-01-26 20:23:52 -05:00
2018-02-12 14:58:50 -05:00
### notLike
2016-01-26 20:23:52 -05:00
2016-07-20 16:33:09 -04:00
Add a 'not like/ and not like' clause to the query
2016-01-26 20:23:52 -05:00
**Parameters**
2018-02-12 14:58:50 -05:00
- `field` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** The name of the field to compare to
- `val` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** The value to compare to
- `pos` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** The placement of the wildcard character(s): before, after, or both (optional, default `both`)
2016-01-26 20:23:52 -05:00
2016-07-20 16:33:09 -04:00
Returns **[QueryBuilder](#querybuilder)** The Query Builder object, for chaining
2016-01-26 20:23:52 -05:00
2018-02-12 14:58:50 -05:00
### orLike
2016-01-26 20:23:52 -05:00
2016-07-20 16:33:09 -04:00
Add an 'or like' clause to the query
2016-01-26 20:23:52 -05:00
**Parameters**
2018-02-12 14:58:50 -05:00
- `field` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** The name of the field to compare to
- `val` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** The value to compare to
- `pos` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** The placement of the wildcard character(s): before, after, or both (optional, default `both`)
2016-01-26 20:23:52 -05:00
2016-07-20 16:33:09 -04:00
Returns **[QueryBuilder](#querybuilder)** The Query Builder object, for chaining
2016-01-26 20:23:52 -05:00
2018-02-12 14:58:50 -05:00
### orNotLike
2016-01-26 20:23:52 -05:00
2016-07-20 16:33:09 -04:00
Add an 'or not like' clause to the query
2016-01-26 20:23:52 -05:00
**Parameters**
2018-02-12 14:58:50 -05:00
- `field` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** The name of the field to compare to
- `val` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** The value to compare to
- `pos` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** The placement of the wildcard character(s): before, after, or both (optional, default `both`)
2016-01-26 20:23:52 -05:00
2016-07-20 16:33:09 -04:00
Returns **[QueryBuilder](#querybuilder)** The Query Builder object, for chaining
2016-01-26 20:23:52 -05:00
2018-02-12 14:58:50 -05:00
### having
2016-01-26 20:23:52 -05:00
2016-07-20 16:33:09 -04:00
Add a 'having' clause
2016-01-26 20:23:52 -05:00
**Parameters**
2018-02-12 14:58:50 -05:00
- `key` **([String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) \| [Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object))** The name of the field and the comparision operator, or an object
- `val` **([String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) \| [Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number))?** The value to compare if the value of key is a string (optional, default `null`)
2016-01-26 20:23:52 -05:00
2016-07-20 16:33:09 -04:00
Returns **[QueryBuilder](#querybuilder)** The Query Builder object, for chaining
2016-01-26 20:23:52 -05:00
2018-02-12 14:58:50 -05:00
### orHaving
2016-01-26 20:23:52 -05:00
2016-07-20 16:33:09 -04:00
Add an 'or having' clause
2016-01-26 20:23:52 -05:00
2016-07-20 16:33:09 -04:00
**Parameters**
2016-01-26 20:23:52 -05:00
2018-02-12 14:58:50 -05:00
- `key` **([String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) \| [Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object))** The name of the field and the comparision operator, or an object
- `val` **([String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) \| [Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number))?** The value to compare if the value of key is a string (optional, default `null`)
2016-01-26 20:23:52 -05:00
2016-07-20 16:33:09 -04:00
Returns **[QueryBuilder](#querybuilder)** The Query Builder object, for chaining
2016-01-26 20:23:52 -05:00
2018-02-12 14:58:50 -05:00
### where
2016-01-26 20:23:52 -05:00
2016-07-20 16:33:09 -04:00
Set a 'where' clause
2016-01-26 20:23:52 -05:00
**Parameters**
2018-02-12 14:58:50 -05:00
- `key` **([String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) \| [Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object))** The name of the field and the comparision operator, or an object
- `val` **([String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) \| [Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number))?** The value to compare if the value of key is a string
2016-01-26 20:23:52 -05:00
2016-07-20 16:33:09 -04:00
Returns **[QueryBuilder](#querybuilder)** The Query Builder object, for chaining
2016-01-26 20:23:52 -05:00
2018-02-12 14:58:50 -05:00
### orWhere
2016-01-26 20:23:52 -05:00
2016-07-20 16:33:09 -04:00
Set a 'or where' clause
2016-01-26 20:23:52 -05:00
**Parameters**
2018-02-12 14:58:50 -05:00
- `key` **([String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) \| [Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object))** The name of the field and the comparision operator, or an object
- `val` **([String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) \| [Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number))?** The value to compare if the value of key is a string
2016-01-26 20:23:52 -05:00
2016-07-20 16:33:09 -04:00
Returns **[QueryBuilder](#querybuilder)** The Query Builder object, for chaining
2016-01-26 20:23:52 -05:00
2018-02-12 14:58:50 -05:00
### whereIsNull
2016-01-26 20:23:52 -05:00
2016-07-20 16:33:09 -04:00
Select a field that is Null
2016-01-26 20:23:52 -05:00
**Parameters**
2018-02-12 14:58:50 -05:00
- `field` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** The name of the field that has a NULL value
2016-01-26 20:23:52 -05:00
2016-07-20 16:33:09 -04:00
Returns **[QueryBuilder](#querybuilder)** The Query Builder object, for chaining
2016-01-26 20:23:52 -05:00
2018-02-12 14:58:50 -05:00
### whereIsNotNull
2016-01-26 20:23:52 -05:00
2016-07-20 16:33:09 -04:00
Specify that a field IS NOT NULL
2016-01-26 20:23:52 -05:00
**Parameters**
2018-02-12 14:58:50 -05:00
- `field` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** The name so the field that is not to be null
2016-01-26 20:23:52 -05:00
2016-07-20 16:33:09 -04:00
Returns **[QueryBuilder](#querybuilder)** The Query Builder object, for chaining
2016-01-26 20:23:52 -05:00
2018-02-12 14:58:50 -05:00
### orWhereIsNull
2016-01-26 20:23:52 -05:00
2016-07-20 16:33:09 -04:00
Field is null prefixed with 'OR'
2016-01-26 20:23:52 -05:00
**Parameters**
2018-02-12 14:58:50 -05:00
- `field` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** The name of the field
2016-01-26 20:23:52 -05:00
2016-07-20 16:33:09 -04:00
Returns **[QueryBuilder](#querybuilder)** The Query Builder object, for chaining
2016-01-26 20:23:52 -05:00
2018-02-12 14:58:50 -05:00
### orWhereIsNotNull
2016-01-26 20:23:52 -05:00
2016-07-20 16:33:09 -04:00
Field is not null prefixed with 'OR'
2016-01-26 20:23:52 -05:00
**Parameters**
2018-02-12 14:58:50 -05:00
- `field` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** The name of the field
2016-01-26 20:23:52 -05:00
2016-07-20 16:33:09 -04:00
Returns **[QueryBuilder](#querybuilder)** The Query Builder object, for chaining
2016-01-26 20:23:52 -05:00
2018-02-12 14:58:50 -05:00
### whereIn
2016-01-26 20:23:52 -05:00
2016-07-20 16:33:09 -04:00
Set a 'where in' clause
2016-01-26 20:23:52 -05:00
**Parameters**
2018-02-12 14:58:50 -05:00
- `key` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** the field to search
- `values` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)** the array of items to search in
2016-01-26 20:23:52 -05:00
2016-07-20 16:33:09 -04:00
Returns **[QueryBuilder](#querybuilder)** The Query Builder object, for chaining
2016-01-26 20:23:52 -05:00
2018-02-12 14:58:50 -05:00
### orWhereIn
2016-01-26 20:23:52 -05:00
2016-07-20 16:33:09 -04:00
Set a 'or where in' clause
2016-01-26 20:23:52 -05:00
**Parameters**
2018-02-12 14:58:50 -05:00
- `key` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** the field to search
- `values` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)** the array of items to search in
2016-01-26 20:23:52 -05:00
2016-07-20 16:33:09 -04:00
Returns **[QueryBuilder](#querybuilder)** The Query Builder object, for chaining
2016-01-26 20:23:52 -05:00
2018-02-12 14:58:50 -05:00
### whereNotIn
2016-01-26 20:23:52 -05:00
2016-07-20 16:33:09 -04:00
Set a 'where not in' clause
2016-01-26 20:23:52 -05:00
**Parameters**
2018-02-12 14:58:50 -05:00
- `key` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** the field to search
- `values` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)** the array of items to search in
2016-01-26 20:23:52 -05:00
2016-07-20 16:33:09 -04:00
Returns **[QueryBuilder](#querybuilder)** The Query Builder object, for chaining
2016-01-26 20:23:52 -05:00
2018-02-12 14:58:50 -05:00
### orWhereNotIn
2016-01-26 20:23:52 -05:00
2016-07-20 16:33:09 -04:00
Set a 'or where not in' clause
2016-01-26 20:23:52 -05:00
2016-07-20 16:33:09 -04:00
**Parameters**
2016-01-26 20:23:52 -05:00
2018-02-12 14:58:50 -05:00
- `key` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** the field to search
- `values` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)** the array of items to search in
2016-01-26 20:23:52 -05:00
2016-07-20 16:33:09 -04:00
Returns **[QueryBuilder](#querybuilder)** The Query Builder object, for chaining
2016-01-26 20:23:52 -05:00
2018-02-12 14:58:50 -05:00
### set
2016-01-26 20:23:52 -05:00
2016-07-20 16:33:09 -04:00
Set values for insertion or updating
2016-01-26 20:23:52 -05:00
2016-07-20 16:33:09 -04:00
**Parameters**
2016-01-26 20:23:52 -05:00
2018-02-12 14:58:50 -05:00
- `key` **([String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) \| [Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object))** The key or object to use
- `val` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** The value if using a scalar key
2016-01-26 20:23:52 -05:00
2016-07-20 16:33:09 -04:00
**Examples**
2016-01-26 20:23:52 -05:00
2016-07-20 16:33:09 -04:00
```javascript
query.set('foo', 'bar'); // Set a key, value pair
```
2016-01-26 20:23:52 -05:00
2016-07-20 16:33:09 -04:00
```javascript
query.set({foo:'bar'}); // Set with an object
```
2016-01-26 20:23:52 -05:00
2016-07-20 16:33:09 -04:00
Returns **[QueryBuilder](#querybuilder)** The Query Builder object, for chaining
2016-01-26 20:23:52 -05:00
2018-02-12 14:58:50 -05:00
### join
2016-01-26 20:23:52 -05:00
2016-07-20 16:33:09 -04:00
Add a join clause to the query
2016-01-26 20:23:52 -05:00
**Parameters**
2018-02-12 14:58:50 -05:00
- `table` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** The table you are joining
- `cond` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** The join condition.
- `type` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** The type of join, which defaults to inner (optional, default `'inner'`)
2016-01-26 20:23:52 -05:00
2016-07-20 16:33:09 -04:00
Returns **[QueryBuilder](#querybuilder)** The Query Builder object, for chaining
2016-01-26 20:23:52 -05:00
2018-02-12 14:58:50 -05:00
### groupBy
2016-01-26 20:23:52 -05:00
2016-07-20 16:33:09 -04:00
Group the results by the selected field(s)
2016-01-26 20:23:52 -05:00
**Parameters**
2018-02-12 14:58:50 -05:00
- `field` **([String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) \| [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array))** The name of the field to group by
2016-01-26 20:23:52 -05:00
2016-07-20 16:33:09 -04:00
Returns **[QueryBuilder](#querybuilder)** The Query Builder object, for chaining
2016-01-26 20:23:52 -05:00
2018-02-12 14:58:50 -05:00
### orderBy
2016-01-26 20:23:52 -05:00
2016-07-20 16:33:09 -04:00
Order the results by the selected field(s)
2016-01-26 20:23:52 -05:00
**Parameters**
2018-02-12 14:58:50 -05:00
- `field` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** The field(s) to order by
- `type` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** The order direction, ASC or DESC (optional, default `'ASC'`)
2016-01-26 20:23:52 -05:00
2016-07-20 16:33:09 -04:00
Returns **[QueryBuilder](#querybuilder)** The Query Builder object, for chaining
2016-01-26 20:23:52 -05:00
2018-02-12 14:58:50 -05:00
### limit
2016-01-26 20:23:52 -05:00
2016-07-20 16:33:09 -04:00
Put a limit on the query
2016-01-26 20:23:52 -05:00
**Parameters**
2018-02-12 14:58:50 -05:00
- `limit` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** The maximum number of rows to fetch
- `offset` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?** The row number to start from
2016-01-26 20:23:52 -05:00
2016-07-20 16:33:09 -04:00
Returns **[QueryBuilder](#querybuilder)** The Query Builder object, for chaining
2016-01-26 20:23:52 -05:00
2018-02-12 14:58:50 -05:00
### groupStart
2016-01-26 20:23:52 -05:00
2016-07-20 16:33:09 -04:00
Adds an open paren to the current query for logical grouping
2016-01-26 20:23:52 -05:00
2016-07-20 16:33:09 -04:00
Returns **[QueryBuilder](#querybuilder)** The Query Builder object, for chaining
2016-01-26 20:23:52 -05:00
2018-02-12 14:58:50 -05:00
### orGroupStart
2016-01-26 20:23:52 -05:00
2016-07-20 16:33:09 -04:00
Adds an open paren to the current query for logical grouping,
prefixed with 'OR'
2016-02-12 11:40:49 -05:00
2016-07-20 16:33:09 -04:00
Returns **[QueryBuilder](#querybuilder)** The Query Builder object, for chaining
2016-02-12 11:40:49 -05:00
2018-02-12 14:58:50 -05:00
### orNotGroupStart
2016-02-12 11:40:49 -05:00
2016-07-20 16:33:09 -04:00
Adds an open paren to the current query for logical grouping,
prefixed with 'OR NOT'
2016-02-12 11:40:49 -05:00
2016-07-20 16:33:09 -04:00
Returns **[QueryBuilder](#querybuilder)** The Query Builder object, for chaining
2016-02-12 11:40:49 -05:00
2018-02-12 14:58:50 -05:00
### groupEnd
2016-01-26 20:23:52 -05:00
2016-07-20 16:33:09 -04:00
Ends a logical grouping started with one of the groupStart methods
2016-01-26 20:23:52 -05:00
2016-07-20 16:33:09 -04:00
Returns **[QueryBuilder](#querybuilder)** The Query Builder object, for chaining
2016-01-26 20:23:52 -05:00
2018-02-12 14:58:50 -05:00
### get
2016-01-26 20:23:52 -05:00
2016-07-20 16:33:09 -04:00
Get the results of the compiled query
2016-01-26 20:23:52 -05:00
**Parameters**
2018-02-12 14:58:50 -05:00
- `table` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** The table to select from
- `limit` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?** A limit for the query
- `offset` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?** An offset for the query
2016-01-26 20:23:52 -05:00
**Examples**
```javascript
2016-07-20 16:33:09 -04:00
query.get('table_name').then(promiseCallback); // Get all the rows in the table
2016-01-26 20:23:52 -05:00
```
```javascript
2016-11-18 22:15:56 -05:00
query.get('table_name', 5); // Get 5 rows from the table
2016-01-26 20:23:52 -05:00
```
2016-07-20 16:33:09 -04:00
```javascript
2016-11-18 22:15:56 -05:00
query.get(); // Get the results of a query generated with other methods
2016-07-20 16:33:09 -04:00
```
2016-01-26 20:23:52 -05:00
2018-02-12 14:58:50 -05:00
Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)&lt;[Result](#result)>** Promise containing the result of the query
2016-01-26 20:23:52 -05:00
2018-02-12 14:58:50 -05:00
### insert
2016-07-20 16:33:09 -04:00
Run the generated insert query
2016-01-26 20:23:52 -05:00
**Parameters**
2018-02-12 14:58:50 -05:00
- `table` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** The table to insert into
- `data` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)?** Data to insert, if not already added with the 'set' method
2016-01-26 20:23:52 -05:00
2018-02-12 14:58:50 -05:00
Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)&lt;[Result](#result)>** Promise containing the result of the query
2016-01-26 20:23:52 -05:00
2018-02-12 14:58:50 -05:00
### insertBatch
2016-01-26 20:23:52 -05:00
2016-07-20 16:33:09 -04:00
Insert multiple sets of rows at a time
2016-01-26 20:23:52 -05:00
2016-07-20 16:33:09 -04:00
**Parameters**
2016-01-26 20:23:52 -05:00
2018-02-12 14:58:50 -05:00
- `table` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** The table to insert into
- `data` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)** The array of objects containing data rows to insert
2016-03-11 16:32:38 -05:00
2016-07-20 16:33:09 -04:00
**Examples**
2016-03-11 16:32:38 -05:00
2016-07-20 16:33:09 -04:00
```javascript
query.insertBatch('foo',[{id:1,val:'bar'},{id:2,val:'baz'}])
.then(promiseCallback);
```
2016-03-11 16:32:38 -05:00
2018-02-12 14:58:50 -05:00
Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)&lt;[Result](#result)>** Promise containing the result of the query
2016-03-11 16:32:38 -05:00
2018-02-12 14:58:50 -05:00
### update
2016-01-26 20:23:52 -05:00
Run the generated update query
**Parameters**
2018-02-12 14:58:50 -05:00
- `table` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** The table to insert into
- `data` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)?** Data to insert, if not already added with the 'set' method
Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)&lt;[Result](#result)>** Promise containing the result of the query
### updateBatch
Creates a batch update sql statement
**Parameters**
- `table` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** The table to update
- `data` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** Batch insert data
- `updateKey` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** The field in the table to compare against for updating
2016-01-26 20:23:52 -05:00
2018-02-12 14:58:50 -05:00
Returns **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** Number of rows updated
2016-01-26 20:23:52 -05:00
2018-02-12 14:58:50 -05:00
### delete
2016-01-26 20:23:52 -05:00
2016-07-20 16:33:09 -04:00
Run the generated delete query
2016-01-26 20:23:52 -05:00
**Parameters**
2018-02-12 14:58:50 -05:00
- `table` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** The table to insert into
- `where` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)?** Where clause for delete statement
2016-01-26 20:23:52 -05:00
2018-02-12 14:58:50 -05:00
Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)&lt;[Result](#result)>** Promise containing the result of the query
2016-01-26 20:23:52 -05:00
2018-02-12 14:58:50 -05:00
### getCompiledSelect
2016-01-26 20:23:52 -05:00
2016-07-20 16:33:09 -04:00
Return generated select query SQL
2016-01-26 20:23:52 -05:00
**Parameters**
2018-02-12 14:58:50 -05:00
- `table` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** the name of the table to retrieve from
- `reset` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Whether to reset the query builder so another query can be built (optional, default `true`)
2016-01-26 20:23:52 -05:00
2018-02-12 14:58:50 -05:00
Returns **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** The compiled sql statement
2016-01-26 20:23:52 -05:00
2018-02-12 14:58:50 -05:00
### getCompiledInsert
2016-01-26 20:23:52 -05:00
2016-07-20 16:33:09 -04:00
Return generated insert query SQL
2016-01-26 20:23:52 -05:00
**Parameters**
2018-02-12 14:58:50 -05:00
- `table` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** the name of the table to insert into
- `reset` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Whether to reset the query builder so another query can be built (optional, default `true`)
2016-01-26 20:23:52 -05:00
2018-02-12 14:58:50 -05:00
Returns **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** The compiled sql statement
2016-01-26 20:23:52 -05:00
2018-02-12 14:58:50 -05:00
### getCompiledUpdate
2016-01-26 20:23:52 -05:00
2016-07-20 16:33:09 -04:00
Return generated update query SQL
2016-01-26 20:23:52 -05:00
**Parameters**
2018-02-12 14:58:50 -05:00
- `table` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** the name of the table to update
- `reset` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Whether to reset the query builder so another query can be built (optional, default `true`)
2016-01-26 20:23:52 -05:00
2018-02-12 14:58:50 -05:00
Returns **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** The compiled sql statement
2016-01-26 20:23:52 -05:00
2018-02-12 14:58:50 -05:00
### getCompiledDelete
2016-01-26 20:23:52 -05:00
2016-07-20 16:33:09 -04:00
Return generated delete query SQL
2016-01-26 20:23:52 -05:00
**Parameters**
2018-02-12 14:58:50 -05:00
- `table` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** the name of the table to delete from
- `reset` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Whether to reset the query builder so another query can be built (optional, default `true`)
2016-01-26 20:23:52 -05:00
2018-02-12 14:58:50 -05:00
Returns **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** The compiled sql statement
2018-02-12 14:58:50 -05:00
## Result
Query result object
**Parameters**
2018-02-12 14:58:50 -05:00
- `rows` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)** the data rows of the result (optional, default `[]`)
- `columns` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)** the column names in the result (optional, default `[]`)
2018-02-12 14:58:50 -05:00
### rowCount
2016-07-20 16:33:09 -04:00
Get the number of rows returned by the query
2018-02-12 14:58:50 -05:00
Returns **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** the number of rows in the result
2018-02-12 14:58:50 -05:00
### columnCount
2016-07-20 16:33:09 -04:00
Get the number of columns returned by the query
2018-02-12 14:58:50 -05:00
Returns **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** the number of columns in the result