Query Builders
Query builders are initialized by calling the appropriate client method. Most builder methods return the builder instance, so method calls can be chained easily. The underlying query will not be executed until execute
is called on the builder instance.
FindManyBuilder
Returns multiple records matching the provided criteria. Example:
execute
Executes the query and returns a Promise with the result.
toQueryBuilder
Transforms the query builder instance into an instance of a Knex query builder.
transaction
Sets the transaction to be used by the query.
select
Sets the SELECT
clause for the query.
selectAll
Sets the SELECT
clause for the query to all possible fields.
addSelect
Adds on to the SELECT
clause for the query.
load
Eager loads the specified model relation. An optional alias can be provided to return the related model or models under a different property name. The getBuilder
parameter is a function that's passed a fresh FindOneBuilder
or FindManyBuilder
instance for the associated model and should return the same kind of Builder instance.
loadPaginated
Eager loads a paginated relation. An optional alias can be provided to return the related models under a different property name. The getBuilder
parameter is a function that's passed a fresh PaginateBuilder
instance for the associated model and should return the same kind of PaginateBuilder instance.
resolveInfo
Modifies the query based on the passed in GraphQLResolveInfo object. The selection set will determine what columns should be selected and which related models should be joined. The where
, orderBy
, limit
and offset
arguments, if they exist on the field and were provided, will be used to set the corresponding clauses in the query.
where
Sets the WHERE
clause for the query.
mergeWhere
Deep merges the provided object with the existing WHERE
options for the query.
orderBy
Sets the ORDER BY
clause for the query.
limit
Sets the LIMIT
for the query.
offset
Sets the OFFSET
for the query.
FindOneBuilder
Returns a single record matching the provided criteria, or null if one cannot be found. Example:
execute
Executes the query and returns a Promise with the result.
toQueryBuilder
Transforms the query builder instance into an instance of a Knex query builder.
transaction
Sets the transaction to be used by the query.
select
Sets the SELECT
clause for the query.
selectAll
Sets the SELECT
clause for the query to all possible fields.
addSelect
Adds on to the SELECT
clause for the query.
load
Eager loads the specified model relation. An optional alias can be provided to return the related model or models under a different property name. The getBuilder
parameter is a function that's passed a fresh FindOneBuilder
or FindManyBuilder
instance for the associated model and should return the same kind of Builder instance.
loadPaginated
Eager loads a paginated relation. An optional alias can be provided to return the related models under a different property name. The getBuilder
parameter is a function that's passed a fresh PaginateBuilder
instance for the associated model and should return the same kind of PaginateBuilder instance.
resolveInfo
Modifies the query based on the passed in GraphQLResolveInfo object. The selection set will determine what columns should be selected and which related models should be joined. The where
, orderBy
, limit
and offset
arguments, if they exist on the field and were provided, will be used to set the corresponding clauses in the query.
where
Sets the WHERE
clause for the query.
mergeWhere
Deep merges the provided object with the existing WHERE
options for the query.
orderBy
Sets the ORDER BY
clause for the query.
limit
Sets the LIMIT
for the query.
offset
Sets the OFFSET
for the query.
FindByIdBuilder
Returns a single record matching the provided primary key value, or null if one cannot be found. Example:
execute
Executes the query and returns a Promise with the result.
toQueryBuilder
Transforms the query builder instance into an instance of a Knex query builder.
transaction
Sets the transaction to be used by the query.
select
Sets the SELECT
clause for the query.
selectAll
Sets the SELECT
clause for the query to all possible fields.
addSelect
Adds on to the SELECT
clause for the query.
load
Eager loads the specified model relation. An optional alias can be provided to return the related model or models under a different property name. The getBuilder
parameter is a function that's passed a fresh FindOneBuilder
or FindManyBuilder
instance for the associated model and should return the same kind of Builder instance.
loadPaginated
Eager loads a paginated relation. An optional alias can be provided to return the related models under a different property name. The getBuilder
parameter is a function that's passed a fresh PaginateBuilder
instance for the associated model and should return the same kind of PaginateBuilder instance.
resolveInfo
Modifies the query based on the passed in GraphQLResolveInfo object. The selection set will determine what columns should be selected and which related models should be joined. The where
, orderBy
, limit
and offset
arguments, if they exist on the field and were provided, will be used to set the corresponding clauses in the query.
CreateOneBuilder
Creates a single record and returns the primary key value of the created record, if supported by the dialect. In MySQL and SQLite, the auto-incremented id value (based on LAST_INSERT_ID
) is returned, if available. Example:
execute
Executes the query and returns a Promise with the result.
toQueryBuilder
Transforms the query builder instance into an instance of a Knex query builder.
transaction
Sets the transaction to be used by the query.
CreateManyBuilder
Creates multiple records and returns the primary key value of the created records, if supported by the dialect. In MySQL and SQLite, the auto-incremented id value (based on LAST_INSERT_ID
) is returned, if available. Example:
execute
Executes the query and returns a Promise with the result.
toQueryBuilder
Transforms the query builder instance into an instance of a Knex query builder.
transaction
Sets the transaction to be used by the query.
UpdateManyBuilder
Updates multiple records based on the provided criteria. Returns the number of affected records. Example:
execute
Executes the query and returns a Promise with the result.
toQueryBuilder
Transforms the query builder instance into an instance of a Knex query builder.
transaction
Sets the transaction to be used by the query.
where
Sets the WHERE
clause for the query.
mergeWhere
Deep merges the provided object with the existing WHERE
options for the query.
orderBy
Sets the ORDER BY
clause for the query.
limit
Sets the LIMIT
for the query.
offset
Sets the OFFSET
for the query.
UpdateByIdBuilder
Updates a single records based on the provided primary key value. Returns a boolean indicating whether the record was found. Example:
execute
Executes the query and returns a Promise with the result.
toQueryBuilder
Transforms the query builder instance into an instance of a Knex query builder.
transaction
Sets the transaction to be used by the query.
DeleteManyBuilder
Deletes multiple records based on the provided criteria. Returns the number of affected records. Example:
execute
Executes the query and returns a Promise with the result.
toQueryBuilder
Transforms the query builder instance into an instance of a Knex query builder.
transaction
Sets the transaction to be used by the query.
where
Sets the WHERE
clause for the query.
mergeWhere
Deep merges the provided object with the existing WHERE
options for the query.
orderBy
Sets the ORDER BY
clause for the query.
limit
Sets the LIMIT
for the query.
offset
Sets the OFFSET
for the query.
DeleteByIdBuilder
Deletes a single records based on the provided primary key value. Returns a boolean indicating whether the record was found. Example:
execute
Executes the query and returns a Promise with the result.
toQueryBuilder
Transforms the query builder instance into an instance of a Knex query builder.
transaction
Sets the transaction to be used by the query.
PaginateBuilder
Returns a "page" object representing a paginated result. Can be used for both pagination or aggregation. Example:
execute
Executes the query and returns a Promise with the result.
toQueryBuilder
Transforms the query builder instance into an instance of a Knex query builder.
transaction
Sets the transaction to be used by the query.
count
Adds the count to the aggregate result object.
min
Adds the minimum for the provided field to the aggregate result object.
max
Adds the maximum for the provided field to the aggregate result object.
avg
Adds the average for the provided field to the aggregate result object.
sum
Adds the sum for the provided field to the aggregate result object.
select
Sets the SELECT
clause for the query.
selectAll
Sets the SELECT
clause for the query to all possible fields.
addSelect
Adds on to the SELECT
clause for the query.
load
Eager loads the specified model relation. An optional alias can be provided to return the related model or models under a different property name. The getBuilder
parameter is a function that's passed a fresh FindOneBuilder
or FindManyBuilder
instance for the associated model and should return the same kind of Builder instance.
loadPaginated
Eager loads a paginated relation. An optional alias can be provided to return the related models under a different property name. The getBuilder
parameter is a function that's passed a fresh PaginateBuilder
instance for the associated model and should return the same kind of PaginateBuilder instance.
resolveInfo
Modifies the query based on the passed in GraphQLResolveInfo object. The selection set will determine what fields to aggregate and return as part of the aggregate result object. The where
, orderBy
, limit
and offset
arguments, if they exist on the field and were provided, will be used to set the corresponding clauses in the query.
where
Sets the WHERE
clause for the query.
mergeWhere
Deep merges the provided object with the existing WHERE
options for the query.
orderBy
Sets the ORDER BY
clause for the query.
limit
Sets the LIMIT
for the query.
offset
Sets the OFFSET
for the query.