node-query/API.md

538 lines
20 KiB
Markdown
Raw Normal View History

<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
2016-01-26 20:23:52 -05:00
# NodeQuery
Class for connection management
**Parameters**
2016-07-20 16:33:09 -04:00
- `config` **[object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** connection parameters
## constructor
Constructor
**Parameters**
2016-07-20 16:33:09 -04:00
- `config` **[object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** connection parameters
**Examples**
```javascript
let nodeQuery = require('ci-node-query')({
driver: 'mysql',
connection: {
host: 'localhost',
user: 'root',
password: '',
database: 'mysql'
}
});
```
```javascript
let nodeQuery = require('ci-node-query')({
driver: 'sqlite',
connection: ':memory:'
});
```
2016-01-26 20:23:52 -05:00
## getQuery
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
# QueryBuilder
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
2016-07-20 16:33:09 -04:00
## 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**
2016-07-20 16:33:09 -04:00
- `sql` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The sql to execute
2016-11-18 22:15:56 -05:00
- `params` **\[[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)]** The query parameters
2016-01-26 20:23:52 -05:00
2016-11-18 22:15:56 -05:00
Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)** Promise with result of query
2016-07-20 16:33:09 -04:00
## resetQuery
Reset the object state for a new query
Returns **void**
## truncate
Empties the selected database table
**Parameters**
- `table` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** the name of the table to truncate
Returns **(void | [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise))** Returns a promise if no callback is supplied
2016-01-26 20:23:52 -05:00
## end
Closes the database connection for the current adapter
Returns **void**
2016-07-20 16:33:09 -04: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**
2016-07-20 16:33:09 -04:00
- `fields` **([String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) \| [Array](https://developer.mozilla.org/en-US/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
2016-07-20 16:33:09 -04: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**
2016-07-20 16:33:09 -04:00
- `tableName` **[String](https://developer.mozilla.org/en-US/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
2016-07-20 16:33:09 -04: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**
2016-07-20 16:33:09 -04:00
- `field` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The name of the field to compare to
- `val` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The value to compare to
- `pos` **\[[String](https://developer.mozilla.org/en-US/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
2016-07-20 16:33:09 -04: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**
2016-07-20 16:33:09 -04:00
- `field` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The name of the field to compare to
- `val` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The value to compare to
- `pos` **\[[String](https://developer.mozilla.org/en-US/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
2016-07-20 16:33:09 -04: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**
2016-07-20 16:33:09 -04:00
- `field` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The name of the field to compare to
- `val` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The value to compare to
- `pos` **\[[String](https://developer.mozilla.org/en-US/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
2016-07-20 16:33:09 -04: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**
2016-07-20 16:33:09 -04:00
- `field` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The name of the field to compare to
- `val` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The value to compare to
- `pos` **\[[String](https://developer.mozilla.org/en-US/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
2016-07-20 16:33:09 -04: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**
2016-07-20 16:33:09 -04:00
- `key` **([String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) \| [Object](https://developer.mozilla.org/en-US/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/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) \| [Number](https://developer.mozilla.org/en-US/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
2016-07-20 16:33:09 -04: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
2016-07-20 16:33:09 -04:00
- `key` **([String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) \| [Object](https://developer.mozilla.org/en-US/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/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) \| [Number](https://developer.mozilla.org/en-US/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
2016-07-20 16:33:09 -04: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**
2016-07-20 16:33:09 -04:00
- `key` **([String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) \| [Object](https://developer.mozilla.org/en-US/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/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) \| [Number](https://developer.mozilla.org/en-US/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
2016-07-20 16:33:09 -04: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**
2016-07-20 16:33:09 -04:00
- `key` **([String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) \| [Object](https://developer.mozilla.org/en-US/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/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) \| [Number](https://developer.mozilla.org/en-US/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
2016-07-20 16:33:09 -04: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**
2016-07-20 16:33:09 -04:00
- `field` **[String](https://developer.mozilla.org/en-US/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
2016-07-20 16:33:09 -04: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**
2016-07-20 16:33:09 -04:00
- `field` **[String](https://developer.mozilla.org/en-US/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
2016-07-20 16:33:09 -04: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**
2016-07-20 16:33:09 -04:00
- `field` **[String](https://developer.mozilla.org/en-US/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
2016-07-20 16:33:09 -04: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**
2016-07-20 16:33:09 -04:00
- `field` **[String](https://developer.mozilla.org/en-US/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
2016-07-20 16:33:09 -04: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**
2016-07-20 16:33:09 -04:00
- `key` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** the field to search
- `values` **[Array](https://developer.mozilla.org/en-US/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
2016-07-20 16:33:09 -04: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**
2016-07-20 16:33:09 -04:00
- `key` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** the field to search
- `values` **[Array](https://developer.mozilla.org/en-US/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
2016-07-20 16:33:09 -04: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**
2016-07-20 16:33:09 -04:00
- `key` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** the field to search
- `values` **[Array](https://developer.mozilla.org/en-US/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
2016-07-20 16:33:09 -04: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
2016-07-20 16:33:09 -04:00
- `key` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** the field to search
- `values` **[Array](https://developer.mozilla.org/en-US/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
2016-07-20 16:33:09 -04: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
2016-07-20 16:33:09 -04:00
- `key` **([String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) \| [Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object))** The key or object to use
- `val` **\[[String](https://developer.mozilla.org/en-US/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
2016-07-20 16:33:09 -04: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**
2016-07-20 16:33:09 -04:00
- `table` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The table you are joining
- `cond` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The join condition.
- `type` **\[[String](https://developer.mozilla.org/en-US/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
2016-07-20 16:33:09 -04: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**
2016-07-20 16:33:09 -04:00
- `field` **([String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) \| [Array](https://developer.mozilla.org/en-US/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
2016-07-20 16:33:09 -04: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**
2016-07-20 16:33:09 -04:00
- `field` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The field(s) to order by
- `type` **\[[String](https://developer.mozilla.org/en-US/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
2016-07-20 16:33:09 -04: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**
2016-07-20 16:33:09 -04:00
- `limit` **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** The maximum number of rows to fetch
- `offset` **\[[Number](https://developer.mozilla.org/en-US/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
2016-07-20 16:33:09 -04: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
2016-07-20 16:33:09 -04: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
2016-07-20 16:33:09 -04: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
2016-07-20 16:33:09 -04: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
2016-07-20 16:33:09 -04: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**
2016-07-20 16:33:09 -04:00
- `table` **\[[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)]** The table to select from
- `limit` **\[[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)]** A limit for the query
- `offset` **\[[Number](https://developer.mozilla.org/en-US/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
2016-11-18 22:35:21 -05:00
Returns **[Promise](https://developer.mozilla.org/en-US/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
2016-07-20 16:33:09 -04:00
## insert
Run the generated insert query
2016-01-26 20:23:52 -05:00
**Parameters**
2016-07-20 16:33:09 -04:00
- `table` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The table to insert into
- `data` **\[[Object](https://developer.mozilla.org/en-US/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
2016-11-18 22:35:21 -05:00
Returns **[Promise](https://developer.mozilla.org/en-US/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
2016-07-20 16:33:09 -04: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
2016-07-20 16:33:09 -04:00
- `table` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The table to insert into
- `data` **[Array](https://developer.mozilla.org/en-US/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
2016-11-18 22:35:21 -05:00
Returns **[Promise](https://developer.mozilla.org/en-US/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
2016-01-26 20:23:52 -05:00
## update
Run the generated update query
**Parameters**
2016-07-20 16:33:09 -04:00
- `table` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The table to insert into
- `data` **\[[Object](https://developer.mozilla.org/en-US/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
2016-11-18 22:35:21 -05:00
Returns **[Promise](https://developer.mozilla.org/en-US/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
2016-07-20 16:33:09 -04: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**
2016-07-20 16:33:09 -04:00
- `table` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The table to insert into
- `where` **\[[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)]** Where clause for delete statement
2016-01-26 20:23:52 -05:00
2016-11-18 22:35:21 -05:00
Returns **[Promise](https://developer.mozilla.org/en-US/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
2016-07-20 16:33:09 -04: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**
2016-07-20 16:33:09 -04:00
- `table` **\[[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)]** the name of the table to retrieve from
- `reset` **\[[Boolean](https://developer.mozilla.org/en-US/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
2016-07-20 16:33:09 -04:00
Returns **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The compiled sql statement
2016-01-26 20:23:52 -05:00
2016-07-20 16:33:09 -04: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**
2016-07-20 16:33:09 -04:00
- `table` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** the name of the table to insert into
- `reset` **\[[Boolean](https://developer.mozilla.org/en-US/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
2016-07-20 16:33:09 -04:00
Returns **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The compiled sql statement
2016-01-26 20:23:52 -05:00
2016-07-20 16:33:09 -04: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**
2016-07-20 16:33:09 -04:00
- `table` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** the name of the table to update
- `reset` **\[[Boolean](https://developer.mozilla.org/en-US/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
2016-07-20 16:33:09 -04:00
Returns **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The compiled sql statement
2016-01-26 20:23:52 -05:00
2016-07-20 16:33:09 -04: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**
2016-07-20 16:33:09 -04:00
- `table` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** the name of the table to delete from
- `reset` **\[[Boolean](https://developer.mozilla.org/en-US/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
2016-07-20 16:33:09 -04:00
Returns **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The compiled sql statement
# Result
Query result object
**Parameters**
2016-07-20 16:33:09 -04:00
- `rows` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)** the data rows of the result
- `columns` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)** the column names in the result
2016-07-20 16:33:09 -04:00
## rowCount
2016-07-20 16:33:09 -04:00
Get the number of rows returned by the query
2016-07-20 16:33:09 -04:00
Returns **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** the number of rows in the result
2016-07-20 16:33:09 -04:00
## columnCount
2016-07-20 16:33:09 -04:00
Get the number of columns returned by the query
2016-07-20 16:33:09 -04:00
Returns **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** the number of columns in the result