# 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

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

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

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

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

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

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

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

  ##### Returns:

  Type
    String

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

  Returns the current class state for testing or other purposes

  Source:
    - query-builder.js, line 352

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

  ##### Returns:

  this

#### groupEnd()

  Ends a logical grouping started with one of the groupStart methods

  Source:
    - query-builder.js, line 728

  ##### Returns:

  this

#### groupStart()

  Adds an open paren to the current query for logical grouping

  Source:
    - query-builder.js, line 692

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

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

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

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

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

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

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

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

  ##### Returns:

  this

#### orGroupStart()

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

  Source:
    - query-builder.js, line 705

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

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

  ##### Returns:

  this

#### orNotGroupStart()

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

  Source:
    - query-builder.js, line 717

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

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

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

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

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

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

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

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

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

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

  ##### Returns:

  this