DerivableRequest
DerivableRequest
is the base protocol for QueryInterfaceRequest
and Association
.
protocol DerivableRequest<RowDecoder> : AggregatingRequest, FilteredRequest, JoinableRequest, OrderedRequest, SelectionRequest, TableRequest
Browse conforming typesMost features of DerivableRequest
come from the protocols it inherits from.
Instance Methods
func aliased(TableAlias
) -> Self Returns a request that can be referred to with the provided alias.
class TableAlias
A TableAlias identifies a table in a request.
The WITH Clause
func with<RowDecoder>(CommonTableExpression<RowDecoder>
) -> Self Embeds a common table expression.
The SELECT Clause
func annotated(with: [any SQLSelectable]
) -> Self Appends result columns to the selected columns.
func annotated(with: any SQLSelectable...
) -> Self Appends result columns to the selected columns.
func annotatedWhenConnected(with: @escaping (Database) throws -> [any SQLSelectable]
) -> Self Appends result columns to the selected columns.
func distinct(
) -> Self Returns a request which returns distinct rows.
func select(any SQLSelectable...
) -> Self Defines the result columns.
func select([any SQLSelectable]
) -> Self Defines the result columns.
func select(literal: SQL
) -> Self Defines the result columns with an
SQL
literal.func select(sql: String, arguments: StatementArguments
) -> Self Defines the result columns with an SQL string.
func selectWhenConnected(@escaping (Database) throws -> [any SQLSelectable]
) -> Self Defines the result columns.
The WHERE Clause
func all(
) -> Self Returns
self
: a request that fetches all rows from this request.func filter(some SQLSpecificExpressible
) -> Self Filters the fetched rows with a boolean SQL expression.
func filter(id: RowDecoder.ID
) -> Self Filters by primary key.
func filter(ids: some Collection<RowDecoder.ID>
) -> Self Filters by primary key.
func filter(key: some DatabaseValueConvertible
) -> Self Filters by primary key.
func filter(key: [String : (any DatabaseValueConvertible)?]?
) -> Self Filters by primary or unique key.
func filter<Keys>(keys: Keys
) -> Self Filters by primary key.
func filter(keys: [[String : (any DatabaseValueConvertible)?]]
) -> Self Filters by primary or unique key.
func filter(literal: SQL
) -> Self Filters the fetched rows with an
SQL
literal.func filter(sql: String, arguments: StatementArguments
) -> Self Filters the fetched rows with an SQL string.
func filterWhenConnected(@escaping (Database) throws -> any SQLExpressible
) -> Self Filters the fetched rows with a boolean SQL expression.
func matching(FTS3Pattern?
) -> Self Filters rows that match an
FTS3
full-text pattern.func matching(FTS5Pattern?
) -> Self Filters rows that match an
FTS5
full-text pattern.func none(
) -> Self Returns an empty request that fetches no row.
The GROUP BY and HAVING Clauses
func group(any SQLExpressible...
) -> Self Returns an aggregate request grouped on the given SQL expressions.
func group([any SQLExpressible]
) -> Self Returns an aggregate request grouped on the given SQL expressions.
func group(literal: SQL
) -> Self Returns an aggregate request grouped on an
SQL
literal.func group(sql: String, arguments: StatementArguments
) -> Self Returns an aggregate request grouped on an SQL string.
func groupByPrimaryKey(
) -> Self Returns an aggregate request grouped on the primary key.
func groupWhenConnected(@escaping (Database) throws -> [any SQLExpressible]
) -> Self Returns an aggregate request grouped on the given SQL expressions.
func having(some SQLExpressible
) -> Self Filters the aggregated groups with a boolean SQL expression.
func having(literal: SQL
) -> Self Filters the aggregated groups with an
SQL
literal.func having(sql: String, arguments: StatementArguments
) -> Self Filters the aggregated groups with an SQL string.
func havingWhenConnected(@escaping (Database) throws -> any SQLExpressible
) -> Self Filters the aggregated groups with a boolean SQL expression.
The ORDER BY Clause
func order(any SQLOrderingTerm...
) -> Self Sorts the fetched rows according to the given SQL ordering terms.
func order([any SQLOrderingTerm]
) -> Self Sorts the fetched rows according to the given SQL ordering terms.
func order(literal: SQL
) -> Self Sorts the fetched rows according to the given
SQL
literal.func order(sql: String, arguments: StatementArguments
) -> Self Sorts the fetched rows according to the given SQL string.
func orderWhenConnected(@escaping (Database) throws -> [any SQLOrderingTerm]
) -> Self Sorts the fetched rows according to the given SQL ordering terms.
func orderByPrimaryKey(
) -> Self Sorts the fetched rows according to the primary key.
func reversed(
) -> Self Returns a request with reversed ordering.
func unordered(
) -> Self Returns a request without any ordering.
func withStableOrder(
) -> Self Returns a request with a stable order.
Associations
func annotated<A>(withOptional: A
) -> Self Appends the columns of the eventual associated record to the selected columns.
func annotated<A>(withRequired: A
) -> Self Appends the columns of the associated record to the selected columns. Records that do not have an associated record are discarded.
func annotated(with: AssociationAggregate<RowDecoder>...
) -> Self Appends association aggregates to the selected columns.
func annotated(with: [AssociationAggregate<RowDecoder>]
) -> Self Appends association aggregates to the selected columns.
func having(AssociationAggregate<RowDecoder>
) -> Self Filters the fetched records with an association aggregate.
func including<A>(all: A
) -> Self Returns a request that fetches all records associated with each record in this request.
func including<A>(optional: A
) -> Self Returns a request that fetches the eventual record associated with each record of this request.
func including<A>(required: A
) -> Self Returns a request that fetches the record associated with each record in this request. Records that do not have an associated record are discarded.
func joining<A>(optional: A
) -> Self Returns a request that joins each record of this request to its eventual associated record.
func joining<A>(required: A
) -> Self Returns a request that joins each record of this request to its associated record. Records that do not have an associated record are discarded.
Supporting Types
protocol AggregatingRequest
A request that can aggregate database rows.
protocol FilteredRequest
A request that can filter database rows.
protocol JoinableRequest<RowDecoder>
A request that can join and prefetch associations.
protocol OrderedRequest
A request that can sort database rows.
protocol SelectionRequest
A request that can define the selected columns.
protocol TableRequest
A request that feeds from a database table
protocol TypedRequest<RowDecoder>
A request that knows how to decode database rows.