- NodeQuery
- QueryBuilder
- queryFile
- query
- resetQuery
- truncate
- end
- select
- from
- like
- notLike
- orLike
- orNotLike
- having
- orHaving
- where
- orWhere
- whereIsNull
- whereIsNotNull
- orWhereIsNull
- orWhereIsNotNull
- whereIn
- orWhereIn
- whereNotIn
- orWhereNotIn
- set
- join
- groupBy
- orderBy
- limit
- groupStart
- orGroupStart
- orNotGroupStart
- groupEnd
- get
- insert
- insertBatch
- update
- updateBatch
- delete
- getCompiledSelect
- getCompiledInsert
- getCompiledUpdate
- getCompiledDelete
- Result
Class for connection management
Parameters
configobject connection parameters
Return an existing query builder instance
Returns QueryBuilder The Query Builder object
Extends QueryBuilderBase
Main object that builds SQL queries.
Parameters
DriverDriver The syntax driver for the databaseAdapterAdapter The database module adapter for running queries
Run a set of queries from a file
Parameters
filestring The path to the sql fileseparatorstring The character separating each query (optional, default';')
Returns Promise The result of all the queries
Run an arbitrary sql query. Run as a prepared statement.
Parameters
Returns Promise Promise with result of query
Reset the object state for a new query
Returns void
Empties the selected database table
Parameters
tablestring the name of the table to truncate
Returns (void | Promise) Returns a promise if no callback is supplied
Closes the database connection for the current adapter
Returns void
Specify rows to select in the query
Parameters
Examples
query.select('foo, bar'); // Select multiple fields with a stringquery.select(['foo', 'bar']); // Select multiple fileds with an arrayReturns QueryBuilder The Query Builder object, for chaining
Specify the database table to select from
Parameters
tableNameString The table to use for the current query
Examples
query.from('tableName');query.from('tableName t'); // Select the table with an aliasReturns QueryBuilder The Query Builder object, for chaining
Add a 'like/ and like' clause to the query
Parameters
fieldString The name of the field to compare tovalString The value to compare toposString The placement of the wildcard character(s): before, after, or both (optional, defaultboth)
Returns QueryBuilder The Query Builder object, for chaining
Add a 'not like/ and not like' clause to the query
Parameters
fieldString The name of the field to compare tovalString The value to compare toposString The placement of the wildcard character(s): before, after, or both (optional, defaultboth)
Returns QueryBuilder The Query Builder object, for chaining
Add an 'or like' clause to the query
Parameters
fieldString The name of the field to compare tovalString The value to compare toposString The placement of the wildcard character(s): before, after, or both (optional, defaultboth)
Returns QueryBuilder The Query Builder object, for chaining
Add an 'or not like' clause to the query
Parameters
fieldString The name of the field to compare tovalString The value to compare toposString The placement of the wildcard character(s): before, after, or both (optional, defaultboth)
Returns QueryBuilder The Query Builder object, for chaining
Add a 'having' clause
Parameters
key(String | Object) The name of the field and the comparision operator, or an objectval(String | Number)? The value to compare if the value of key is a string (optional, defaultnull)
Returns QueryBuilder The Query Builder object, for chaining
Add an 'or having' clause
Parameters
key(String | Object) The name of the field and the comparision operator, or an objectval(String | Number)? The value to compare if the value of key is a string (optional, defaultnull)
Returns QueryBuilder The Query Builder object, for chaining
Set a 'where' clause
Parameters
key(String | Object) The name of the field and the comparision operator, or an objectval(String | Number)? The value to compare if the value of key is a string
Returns QueryBuilder The Query Builder object, for chaining
Set a 'or where' clause
Parameters
key(String | Object) The name of the field and the comparision operator, or an objectval(String | Number)? The value to compare if the value of key is a string
Returns QueryBuilder The Query Builder object, for chaining
Select a field that is Null
Parameters
fieldString The name of the field that has a NULL value
Returns QueryBuilder The Query Builder object, for chaining
Specify that a field IS NOT NULL
Parameters
fieldString The name so the field that is not to be null
Returns QueryBuilder The Query Builder object, for chaining
Field is null prefixed with 'OR'
Parameters
fieldString The name of the field
Returns QueryBuilder The Query Builder object, for chaining
Field is not null prefixed with 'OR'
Parameters
fieldString The name of the field
Returns QueryBuilder The Query Builder object, for chaining
Set a 'where in' clause
Parameters
Returns QueryBuilder The Query Builder object, for chaining
Set a 'or where in' clause
Parameters
Returns QueryBuilder The Query Builder object, for chaining
Set a 'where not in' clause
Parameters
Returns QueryBuilder The Query Builder object, for chaining
Set a 'or where not in' clause
Parameters
Returns QueryBuilder The Query Builder object, for chaining
Set values for insertion or updating
Parameters
Examples
query.set('foo', 'bar'); // Set a key, value pairquery.set({foo:'bar'}); // Set with an objectReturns QueryBuilder The Query Builder object, for chaining
Add a join clause to the query
Parameters
tableString The table you are joiningcondString The join condition.typeString The type of join, which defaults to inner (optional, default'inner')
Returns QueryBuilder The Query Builder object, for chaining
Group the results by the selected field(s)
Parameters
Returns QueryBuilder The Query Builder object, for chaining
Order the results by the selected field(s)
Parameters
fieldString The field(s) to order bytypeString The order direction, ASC or DESC (optional, default'ASC')
Returns QueryBuilder The Query Builder object, for chaining
Put a limit on the query
Parameters
Returns QueryBuilder The Query Builder object, for chaining
Adds an open paren to the current query for logical grouping
Returns QueryBuilder The Query Builder object, for chaining
Adds an open paren to the current query for logical grouping, prefixed with 'OR'
Returns QueryBuilder The Query Builder object, for chaining
Adds an open paren to the current query for logical grouping, prefixed with 'OR NOT'
Returns QueryBuilder The Query Builder object, for chaining
Ends a logical grouping started with one of the groupStart methods
Returns QueryBuilder The Query Builder object, for chaining
Get the results of the compiled query
Parameters
tableString? The table to select fromlimitNumber? A limit for the queryoffsetNumber? An offset for the query
Examples
query.get('table_name').then(promiseCallback); // Get all the rows in the tablequery.get('table_name', 5); // Get 5 rows from the tablequery.get(); // Get the results of a query generated with other methodsReturns Promise<Result> Promise containing the result of the query
Run the generated insert query
Parameters
tableString The table to insert intodataObject? Data to insert, if not already added with the 'set' method
Returns Promise<Result> Promise containing the result of the query
Insert multiple sets of rows at a time
Parameters
tableString The table to insert intodataArray The array of objects containing data rows to insert
Examples
query.insertBatch('foo',[{id:1,val:'bar'},{id:2,val:'baz'}])
.then(promiseCallback);Returns Promise<Result> Promise containing the result of the query
Run the generated update query
Parameters
tableString The table to insert intodataObject? Data to insert, if not already added with the 'set' method
Returns Promise<Result> Promise containing the result of the query
Creates a batch update sql statement
Parameters
tableString The table to updatedataObject Batch insert dataupdateKeyString The field in the table to compare against for updating
Returns Number Number of rows updated
Run the generated delete query
Parameters
Returns Promise<Result> Promise containing the result of the query
Return generated select query SQL
Parameters
tableString? the name of the table to retrieve fromresetBoolean Whether to reset the query builder so another query can be built (optional, defaulttrue)
Returns String The compiled sql statement
Return generated insert query SQL
Parameters
tableString the name of the table to insert intoresetBoolean Whether to reset the query builder so another query can be built (optional, defaulttrue)
Returns String The compiled sql statement
Return generated update query SQL
Parameters
tableString the name of the table to updateresetBoolean Whether to reset the query builder so another query can be built (optional, defaulttrue)
Returns String The compiled sql statement
Return generated delete query SQL
Parameters
tableString the name of the table to delete fromresetBoolean Whether to reset the query builder so another query can be built (optional, defaulttrue)
Returns String The compiled sql statement
Query result object
Parameters
rowsArray the data rows of the result (optional, default[])columnsArray the column names in the result (optional, default[])
Get the number of rows returned by the query
Returns Number the number of rows in the result
Get the number of columns returned by the query
Returns Number the number of columns in the result