Set the limit clause
(String)
SQL statement to modify
(Number)
Maximum number of rows to fetch
([Number])
Number of rows to skip
String
:
Modified SQL statement
Quote database table name, and set prefix
(String)
Table name to quote
String
:
Quoted table name
Use the driver's escape character to quote identifiers
(String | Array)
:
Quoted identifier(s)
Generate SQL to truncate the passed table
(String)
Table to truncate
String
:
Truncation SQL
Generate SQL to insert a group of rows
String
:
Query and data to insert
Class for connection management
(object)
connection parameters
Constructor
(object)
connection parameters
let nodeQuery = require('ci-node-query')({
driver: 'mysql',
connection: {
host: 'localhost',
user: 'root',
password: '',
database: 'mysql'
}
});
let nodeQuery = require('ci-node-query')({
driver: 'sqlite',
connection: ':memory:'
});
Return an existing query builder instance
QueryBuilder
:
The Query Builder object
Main object that builds SQL queries.
Extends QueryBuilderBase
(Driver)
The syntax driver for the database
(Adapter)
The database module adapter for running queries
Reset the object state for a new query
void
:
Closes the database connection for the current adapter
void
:
Specify rows to select in the query
QueryBuilder
:
The Query Builder object, for chaining
query.select('foo, bar'); // Select multiple fields with a string
query.select(['foo', 'bar']); // Select multiple fileds with an array
Specify the database table to select from
(String)
The table to use for the current query
QueryBuilder
:
The Query Builder object, for chaining
query.from('tableName');
query.from('tableName t'); // Select the table with an alias
Add a 'like/ and like' clause to the query
(String)
The name of the field to compare to
(String)
The value to compare to
([String]
(default both
)
)
The placement of the wildcard character(s): before, after, or both
QueryBuilder
:
The Query Builder object, for chaining
Add a 'not like/ and not like' clause to the query
(String)
The name of the field to compare to
(String)
The value to compare to
([String]
(default both
)
)
The placement of the wildcard character(s): before, after, or both
QueryBuilder
:
The Query Builder object, for chaining
Add an 'or like' clause to the query
(String)
The name of the field to compare to
(String)
The value to compare to
([String]
(default both
)
)
The placement of the wildcard character(s): before, after, or both
QueryBuilder
:
The Query Builder object, for chaining
Add an 'or not like' clause to the query
(String)
The name of the field to compare to
(String)
The value to compare to
([String]
(default both
)
)
The placement of the wildcard character(s): before, after, or both
QueryBuilder
:
The Query Builder object, for chaining
Add a 'having' clause
QueryBuilder
:
The Query Builder object, for chaining
Add an 'or having' clause
QueryBuilder
:
The Query Builder object, for chaining
Set a 'where' clause
QueryBuilder
:
The Query Builder object, for chaining
Set a 'or where' clause
QueryBuilder
:
The Query Builder object, for chaining
Select a field that is Null
(String)
The name of the field that has a NULL value
QueryBuilder
:
The Query Builder object, for chaining
Specify that a field IS NOT NULL
(String)
The name so the field that is not to be null
QueryBuilder
:
The Query Builder object, for chaining
Field is null prefixed with 'OR'
(String)
The name of the field
QueryBuilder
:
The Query Builder object, for chaining
Field is not null prefixed with 'OR'
(String)
The name of the field
QueryBuilder
:
The Query Builder object, for chaining
Set a 'where in' clause
QueryBuilder
:
The Query Builder object, for chaining
Set a 'or where in' clause
QueryBuilder
:
The Query Builder object, for chaining
Set a 'where not in' clause
QueryBuilder
:
The Query Builder object, for chaining
Set a 'or where not in' clause
QueryBuilder
:
The Query Builder object, for chaining
Set values for insertion or updating
QueryBuilder
:
The Query Builder object, for chaining
query.set('foo', 'bar'); // Set a key, value pair
query.set({foo:'bar'}); // Set with an object
Add a join clause to the query
(String)
The table you are joining
(String)
The join condition.
([String]
(default 'inner'
)
)
The type of join, which defaults to inner
QueryBuilder
:
The Query Builder object, for chaining
Group the results by the selected field(s)
QueryBuilder
:
The Query Builder object, for chaining
Order the results by the selected field(s)
(String)
The field(s) to order by
([String]
(default 'ASC'
)
)
The order direction, ASC or DESC
QueryBuilder
:
The Query Builder object, for chaining
Put a limit on the query
QueryBuilder
:
The Query Builder object, for chaining
Adds an open paren to the current query for logical grouping
QueryBuilder
:
The Query Builder object, for chaining
Adds an open paren to the current query for logical grouping, prefixed with 'OR'
QueryBuilder
:
The Query Builder object, for chaining
Adds an open paren to the current query for logical grouping, prefixed with 'OR NOT'
QueryBuilder
:
The Query Builder object, for chaining
Ends a logical grouping started with one of the groupStart methods
QueryBuilder
:
The Query Builder object, for chaining
Get the results of the compiled query
([String])
The table to select from
([Number])
A limit for the query
([Number])
An offset for the query
([Function])
A callback for receiving the result
(void | Promise)
:
If no callback is passed, a promise is returned
query.get('table_name').then(promiseCallback); // Get all the rows in the table
query.get('table_name', 5, callback); // Get 5 rows from the table
query.get(callback); // Get the results of a query generated with other methods
Run the generated insert query
(String)
The table to insert into
([Object])
Data to insert, if not already added with the 'set' method
([Function])
Callback for handling response from the database
(void | Promise)
:
If no callback is passed, a promise is returned
Insert multiple sets of rows at a time
(String)
The table to insert into
(Array)
The array of objects containing data rows to insert
([Function])
Callback for handling database response
(void | Promise)
:
If no callback is passed, a promise is returned
query.insertBatch('foo',[{id:1,val:'bar'},{id:2,val:'baz'}], callbackFunction);
query.insertBatch('foo',[{id:1,val:'bar'},{id:2,val:'baz'}])
.then(promiseCallback);
Run the generated update query
(String)
The table to insert into
([Object])
Data to insert, if not already added with the 'set' method
([Function])
Callback for handling response from the database
(void | Promise)
:
If no callback is passed, a promise is returned
Query result object