# 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 12

### Methods

#### 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 399

  ##### 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 741

  ##### 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 862

  ##### 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 840

  ##### 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 824

  ##### 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 851

  ##### Returns:

  Type
    String

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

  Returns the current class state for testing or other purposes

  Source:
    - query-builder.js, line 346

  ##### 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 623

  ##### Returns:

  this

#### groupEnd()

  Ends a logical grouping started with one of the groupStart methods

  Source:
    - query-builder.js, line 722

  ##### Returns:

  this

#### groupStart()

  Adds an open paren to the current query for logical grouping

  Source:
    - query-builder.js, line 686

  ##### 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 472

  ##### 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 764

  ##### Returns:

  void

#### 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 598

  ##### 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 421

  ##### 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 674

  ##### 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 434

  ##### 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 646

  ##### Returns:

  this

#### orGroupStart()

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

  Source:
    - query-builder.js, line 699

  ##### 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 486

  ##### 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 447

  ##### Returns:

  this

#### orNotGroupStart()

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

  Source:
    - query-builder.js, line 711

  ##### 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 460

  ##### 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 512

  ##### 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 536

  ##### 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 560

  ##### 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 365

  ##### 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 572

  ##### 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 782

  ##### 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 500

  ##### 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 524

  ##### 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 548

  ##### Returns:

  this

#### <inner> 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 792

  ##### Returns:

  void