The model class that is created for results of this query.
Protected
Readonly
ModelThe model class that is created for results of this query.
Protected
appliedProtected
constraintsConstraints applied to this query.
Protected
Readonly
databaseProtected
eagerProtected
Optional
rawRaw SQL to use instead. Overrides builder methods.
Protected
Optional
registeredThe connection on which the query should be executed.
Protected
registeredIf true, the query should refer to distinct records.
Protected
registeredThe fields to query from the table.
Protected
registeredArray of SQL group-by clauses.
Protected
registeredArray of SQL order-by clauses.
Protected
Optional
registeredThe number of records to skip before the result set.
Protected
Optional
registeredThe max number of records to include in the result set.
Protected
Optional
sourceThe source table to query from.
Private
appThe global application instance.
Get the constraints applied to this query.
True if the query should be DISTINCT
Get the fields that should be included in this query.
Get the SQL group-by clauses applied to this query.
Get the SQL order-by clauses applied to this query.
Get the skip/take values of this query.
Get the source table for this query.
Protected
appGet the global Application.
Remove all selected fields from this query.
Create a copy of this builder. to add implementation-specific pass-alongs.
Specify the connection name or instance to execute the query on.
Protected
containerExecute a DELETE based on this query.
query.table('my_table').where('id', <, 44).delete()
This is equivalent to:
DELETE
FROM my_table
WHERE
id < 44
Make the query return only distinct rows.
Include the given field (and optional alias) in the query.
Optional
alias: stringInclude the given fields in the query.
Rest
...fields: SpecifiedField[]Get a copy of this builder with all of its values finalized. to apply scopes
Set the source table (and optional alias) for this query.
Optional
alias: stringGet an async collection of the rows resulting from this query.
Get the method with the given name from this class, bound to this class.
function
Get the method with the given name from this class, bound to this class.
function
Rest
...args: any[]Create a new, empty, instance of the current builder.
Get a result iterable for the built query.
Apply one or more GROUP-BY clauses to the query.
Rest
...groupings: string[]Insert the given rows into the table for this query, returning the fields specified in this query.
const rows = [
{ name: 'A' },
{ name: 'B' },
]
query.table('my_table')
.returning('id', 'name')
.insert(rows)
This is equivalent to:
INSERT INTO my_table (name)
VALUES ('A'), ('B')
RETURNING id, name
Get a result iterable for the rows of this query.
Limit the query to a maximum number of rows.
Protected
makeProtected
normalizeAllow the query to return non-distinct rows. (Undoes distinct()
.)
Alias of skip()
.
Apply an OR WHERE constraint to the query.
Optional
operator: ConstraintOperatorOptional
operand: EscapeValue<ScalarEscapeValue>Apply an OR WHERE IN constraint to the query, escaping the values in the set.
Apply an OR WHERE NOT constraint to the query.
Optional
operator: ConstraintOperatorOptional
operand: EscapeValue<ScalarEscapeValue>Apply an OR WHERE NOT IN constraint to the query, escaping the values in the set.
Apply an OR WHERE constraint to the query, without escaping operand
. Prefer orWhere()
.
Order the query by the given field.
Order the query by the given field, ascending.
Order the query by the given field, descending.
Apply skip()
and take()
calls to retrieve the records that should appear on
the pageNum
page, assuming each page has pageSize
many records.
Set the query manually. Overrides any builder methods.
(new Builder())
.raw('SELECT NOW() AS example_column')
.get()
Alias of fields()
.
Rest
...fields: SpecifiedField[]Alias of fields()
.
Rest
...fields: SpecifiedField[]Skip the first rows
many rows in the result set.
Alias of from()
.
Optional
alias: stringAlias of limit()
.
Pass this instance into a callback, then return this instance for chaining.
Run an UPDATE query for all rows matched by this query, setting the given data.
query.table('my_table').update({ my_col: 4 })
This is equivalent to:
UPDATE TO my_table
SET
my_col = 4
Run a batch update on all rows matched by this query, setting the values for discrete rows based on some key.
This is a more efficient way of combining discrete update queries.
query.table('my_table')
.updateMany('id_col', [
{id_col: 1, val1_col: 'a'},
{id_col: 2, val2_col: 'b'},
])
This will set the val1_col
to a
for rows where id_col
is 1
and so on.
Apply a new WHERE constraint to the query.
Optional
operator: ConstraintOperatorOptional
operand: EscapeValue<ScalarEscapeValue>Apply a WHERE IN constraint to the query, escaping the values in the set.
Apply a WHERE...IN... constraint on the primary key of the model.
Apply an impossible constraint to the query, causing it to match 0 rows.
Apply a new WHERE NOT constraint to the query.
Optional
operator: ConstraintOperatorOptional
operand: EscapeValue<ScalarEscapeValue>Apply a WHERE NOT IN constraint to the query, escaping the values in the set.
Apply a WHERE ... IS NOT NULL constraint to the query.
Apply a WHERE ... IS NULL constraint to the query.
Apply a where constraint on the column corresponding the the specified property on the model.
Optional
operand: EscapeValue<ScalarEscapeValue>Add raw SQL as a constraint to the query.
Apply a new WHERE constraint to the query, without escaping operand
. Prefer where()
.
Mark a relation to be eager-loaded.
Prevent a relation from being eager-loaded.
Remove a specific scope from this query by its identifier.
Remove all global scopes from this query.
Implementation of the abstract builder whose results yield instances of a given Model,
T
.