# Module: query-builder

## query-builder

Source:
  - query-builder.js, line 3

### Members

#### <private, inner> state

  Variables controlling the sql building

  Source:
    - query-builder.js, line 13

### 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:
    - query-builder.js, line 859

  ##### Returns:

  void

#### end()

  Closes the database connection for the current adapter

  Source:
    - query-builder.js, line 347

  ##### 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:
    - query-builder.js, line 395

  ##### 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:
    - query-builder.js, line 781

  ##### 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:
    - query-builder.js, line 921

  ##### 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:
    - query-builder.js, line 899

  ##### 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:
    - query-builder.js, line 882

  ##### 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:
    - query-builder.js, line 910

  ##### Returns:

  Type
    String

#### <private> getState() → {Object}

  Returns the current class state for testing or other purposes

  Source:
    - query-builder.js, line 338

  ##### Returns:

  Type
    Object

#### groupBy(field)

  Group the results by the selected field(s)

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `field` | String | Array |

  Source:
    - query-builder.js, line 663

  ##### Returns:

  this

#### groupEnd()

  Ends a logical grouping started with one of the groupStart methods

  Source:
    - query-builder.js, line 762

  ##### Returns:

  this

#### groupStart()

  Adds an open paren to the current query for logical grouping

  Source:
    - query-builder.js, line 726

  ##### 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:
    - query-builder.js, line 468

  ##### 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:
    - query-builder.js, line 804

  ##### 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:
    - query-builder.js, line 824

  ##### 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:
    - query-builder.js, line 638

  ##### 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:
    - query-builder.js, line 417

  ##### 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:
    - query-builder.js, line 714

  ##### 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:
    - query-builder.js, line 430

  ##### 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:
    - query-builder.js, line 686

  ##### Returns:

  this

#### orGroupStart()

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

  Source:
    - query-builder.js, line 739

  ##### 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:
    - query-builder.js, line 482

  ##### 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:
    - query-builder.js, line 443

  ##### Returns:

  this

#### orNotGroupStart()

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

  Source:
    - query-builder.js, line 751

  ##### 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:
    - query-builder.js, line 456

  ##### 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:
    - query-builder.js, line 508

  ##### 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:
    - query-builder.js, line 576

  ##### Returns:

  this

#### orWhereIsNotNull(field)

  Field is not null prefixed with 'OR'

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `field` | String |

  Source:
    - query-builder.js, line 552

  ##### Returns:

  this

#### orWhereIsNull(field)

  Field is null prefixed with 'OR'

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `field` | String |

  Source:
    - query-builder.js, line 541

  ##### 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:
    - query-builder.js, line 600

  ##### 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:
    - query-builder.js, line 361

  ##### 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:
    - query-builder.js, line 612

  ##### 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:
    - query-builder.js, line 840

  ##### 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:
    - query-builder.js, line 496

  ##### 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:
    - query-builder.js, line 564

  ##### Returns:

  this

#### whereIsNotNull(field)

  Specify that a field IS NOT NULL

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `field` | String |

  Source:
    - query-builder.js, line 530

  ##### Returns:

  this

#### whereIsNull(field)

  Select a field that is Null

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `field` | String | The name of the field that has a NULL value

  Source:
    - query-builder.js, line 519

  ##### 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:
    - query-builder.js, line 588

  ##### Returns:

  this