joining(optional:)
Returns a request that joins each record of this request to its eventual associated record.
static func joining<A>(optional association: A) -> QueryInterfaceRequest<Self> where Self == A.OriginRowDecoder, A : Association
Returns a request that joins each record of this request to its eventual associated record.
static func joining<A>(optional association: A) -> QueryInterfaceRequest<Self> where Self == A.OriginRowDecoder, A : Association
s4GRDB11TableRecordPAAE7joining8optionalAA21QueryInterfaceRequestVyxGqd___t16OriginRowDecoderQyd__RszAA11AssociationRd__lFZ
What are these?997JK
import GRDB
A toolkit for SQLite databases, with a focus on application development
protocol TableRecord
A type that builds database queries with the Swift language instead of SQL.
struct QueryInterfaceRequest<RowDecoder>
A request that builds SQL queries with Swift.
associatedtype OriginRowDecoder
The record type at the origin of the association.
protocol Association : DerivableRequest, Sendable
A type that defines a connection between two tables.
static func aliased(_ alias: TableAlias) -> QueryInterfaceRequest<Self>
Returns a request that can be referred to with the provided alias.
static func all() -> QueryInterfaceRequest<Self>
Returns a request for all records in the table.
static func annotated(with selection: [any SQLSelectable]) -> QueryInterfaceRequest<Self>
Returns a request with the provided result columns appended to the record selection.
static func annotated(with aggregates: AssociationAggregate<Self>...) -> QueryInterfaceRequest<Self>
Returns a request with the given association aggregates appended to the record selection.
static func annotated(with aggregates: [AssociationAggregate<Self>]) -> QueryInterfaceRequest<Self>
Returns a request with the given association aggregates appended to the record selection.
static func annotated(with selection: any SQLSelectable...) -> QueryInterfaceRequest<Self>
Returns a request with the provided result columns appended to the record selection.
static func annotated<A>(withOptional association: A) -> QueryInterfaceRequest<Self> where Self == A.OriginRowDecoder, A : Association
Returns a request with the columns of the eventual associated record appended to the record selection.
static func annotated<A>(withRequired association: A) -> QueryInterfaceRequest<Self> where Self == A.OriginRowDecoder, A : Association
Returns a request with the columns of the associated record appended to the record selection. Records that do not have an associated record are discarded.
static func filter(_ predicate: some SQLSpecificExpressible) -> QueryInterfaceRequest<Self>
Returns a request filtered with a boolean SQL expression.
static func filter(id: ID) -> QueryInterfaceRequest<Self>
Returns a request filtered by primary key.
static func filter(ids: some Collection<ID>) -> QueryInterfaceRequest<Self>
Returns a request filtered by primary key.
static func filter(key: [String : (any DatabaseValueConvertible)?]?) -> QueryInterfaceRequest<Self>
Returns a request filtered by primary or unique key.
static func filter(key: some DatabaseValueConvertible) -> QueryInterfaceRequest<Self>
Returns a request filtered by primary key.
static func filter(keys: [[String : (any DatabaseValueConvertible)?]]) -> QueryInterfaceRequest<Self>
Returns a request filtered by primary or unique key.
static func filter(keys: some Collection<some DatabaseValueConvertible>) -> QueryInterfaceRequest<Self>
Returns a request filtered by primary key.
static func filter(literal sqlLiteral: SQL) -> QueryInterfaceRequest<Self>
Returns a request filtered with an SQL
literal.
static func filter(sql: String, arguments: StatementArguments = StatementArguments()) -> QueryInterfaceRequest<Self>
Returns a request filtered with an SQL string.
static func having(_ predicate: AssociationAggregate<Self>) -> QueryInterfaceRequest<Self>
Returns a request filtered according to the provided association aggregate.
static func including<A>(all association: A) -> QueryInterfaceRequest<Self> where Self == A.OriginRowDecoder, A : AssociationToMany
Returns a request that fetches all records associated with each record in this request.
static func including<A>(optional association: A) -> QueryInterfaceRequest<Self> where Self == A.OriginRowDecoder, A : Association
Returns a request that fetches the eventual record associated with each record of this request.
static func including<A>(required association: A) -> QueryInterfaceRequest<Self> where Self == A.OriginRowDecoder, A : Association
Returns a request that fetches the record associated with each record in this request. Records that do not have an associated record are discarded.
static func joining<A>(required association: A) -> QueryInterfaceRequest<Self> where Self == A.OriginRowDecoder, A : Association
Returns a request that joins each record of this request to its associated record. Records that do not have an associated record are discarded.
static func limit(_ limit: Int, offset: Int? = nil) -> QueryInterfaceRequest<Self>
Returns a limited request.
static func matching(_ pattern: FTS3Pattern?) -> QueryInterfaceRequest<Self>
Returns a request filtered on records that match an FTS3
full-text pattern.
static func matching(_ pattern: FTS5Pattern?) -> QueryInterfaceRequest<Self>
Returns a request filtered on records that match an FTS5
full-text pattern.
static func none() -> QueryInterfaceRequest<Self>
Returns an empty request that fetches no record.
static func order(_ orderings: [any SQLOrderingTerm]) -> QueryInterfaceRequest<Self>
Returns a request sorted according to the given SQL ordering terms.
static func order(_ orderings: any SQLOrderingTerm...) -> QueryInterfaceRequest<Self>
Returns a request sorted according to the given SQL ordering terms.
static func order(literal sqlLiteral: SQL) -> QueryInterfaceRequest<Self>
Returns a request sorted according to the given SQL
literal.
static func order(sql: String, arguments: StatementArguments = StatementArguments()) -> QueryInterfaceRequest<Self>
Returns a request sorted according to the given SQL string.
static func orderByPrimaryKey() -> QueryInterfaceRequest<Self>
Returns a request sorted by primary key.
func request<A>(for association: A) -> QueryInterfaceRequest<A.RowDecoder> where Self == A.OriginRowDecoder, A : Association
Returns a request for the associated record(s).
static func select(_ selection: [any SQLSelectable]) -> QueryInterfaceRequest<Self>
Returns a request that selects the provided result columns.
static func select(_ selection: any SQLSelectable...) -> QueryInterfaceRequest<Self>
Returns a request that selects the provided result columns.
static func select<RowDecoder>(_ selection: any SQLSelectable..., as type: RowDecoder.Type = RowDecoder.self) -> QueryInterfaceRequest<RowDecoder>
Returns a request that selects the provided result columns, and defines the type of decoded rows.
static func select<RowDecoder>(_ selection: [any SQLSelectable], as type: RowDecoder.Type = RowDecoder.self) -> QueryInterfaceRequest<RowDecoder>
Returns a request that selects the provided result columns, and defines the type of decoded rows.
static func select(literal sqlLiteral: SQL) -> QueryInterfaceRequest<Self>
Returns a request that selects the provided SQL
literal.
static func select<RowDecoder>(literal sqlLiteral: SQL, as type: RowDecoder.Type = RowDecoder.self) -> QueryInterfaceRequest<RowDecoder>
Returns a request that selects the provided SQL
literal, and defines the type of decoded rows.
static func select(sql: String, arguments: StatementArguments = StatementArguments()) -> QueryInterfaceRequest<Self>
Returns a request that selects the provided SQL string.
static func select<RowDecoder>(sql: String, arguments: StatementArguments = StatementArguments(), as type: RowDecoder.Type = RowDecoder.self) -> QueryInterfaceRequest<RowDecoder>
Returns a request that selects the provided SQL string, and defines the type of decoded rows.
static func selectID() -> QueryInterfaceRequest<Self.ID> where Self : Identifiable
Returns a request that selects the primary key.
static func selectPrimaryKey<PrimaryKey>(as type: PrimaryKey.Type = PrimaryKey.self) -> QueryInterfaceRequest<PrimaryKey>
Returns a request that selects the primary key.
static func with<RowDecoder>(_ cte: CommonTableExpression<RowDecoder>) -> QueryInterfaceRequest<Self>
Returns a request that embeds a common table expression.
static var databaseSelection: [any SQLSelectable] { get }
The default selection is all columns: [.allColumns]
.
static var databaseTableName: String { get }
The default name of the database table is derived from the name of the type.
static func association<Destination>(to cte: CommonTableExpression<Destination>) -> JoinAssociation<Self, Destination>
Creates an association to a common table expression.
static func association<Destination>(to cte: CommonTableExpression<Destination>, on condition: @escaping (_ left: TableAlias, _ right: TableAlias) -> any SQLExpressible) -> JoinAssociation<Self, Destination>
Creates an association to a common table expression.
static func belongsTo<Destination>(_ destination: Table<Destination>, key: String? = nil, using foreignKey: ForeignKey? = nil) -> BelongsToAssociation<Self, Destination>
Creates a BelongsToAssociation
between Self
and the destination Table
.
static func belongsTo<Destination>(_ destination: Destination.Type, key: String? = nil, using foreignKey: ForeignKey? = nil) -> BelongsToAssociation<Self, Destination> where Destination : TableRecord
Creates a BelongsToAssociation
between Self
and the destination TableRecord
type.
@discardableResult static func deleteAll(_ db: Database) throws -> Int
Deletes all records, and returns the number of deleted records.
@discardableResult static func deleteAll(_ db: Database, keys: [[String : (any DatabaseValueConvertible)?]]) throws -> Int
Deletes records identified by their primary or unique keys, and returns the number of deleted records.
@discardableResult static func deleteAll(_ db: Database, keys: some Collection<some DatabaseValueConvertible>) throws -> Int
Deletes records identified by their primary keys, and returns the number of deleted records.
@discardableResult static func deleteOne(_ db: Database, key: [String : (any DatabaseValueConvertible)?]) throws -> Bool
Deletes the record identified by its primary or unique key, and returns whether a record was deleted.
@discardableResult static func deleteOne(_ db: Database, key: some DatabaseValueConvertible) throws -> Bool
Deletes the record identified by its primary key, and returns whether a record was deleted.
static func exists(_ db: Database, key: [String : (any DatabaseValueConvertible)?]) throws -> Bool
Returns whether a record exists for this primary or unique key.
static func exists(_ db: Database, key: some DatabaseValueConvertible) throws -> Bool
Returns whether a record exists for this primary key.
static func fetchCount(_ db: Database) throws -> Int
Returns the number of records in the database table.
static func hasMany<Destination>(_ destination: Table<Destination>, key: String? = nil, using foreignKey: ForeignKey? = nil) -> HasManyAssociation<Self, Destination>
Creates a HasManyAssociation
between Self
and the destination Table
.
static func hasMany<Destination>(_ destination: Destination.Type, key: String? = nil, using foreignKey: ForeignKey? = nil) -> HasManyAssociation<Self, Destination> where Destination : TableRecord
Creates a HasManyAssociation
between Self
and the destination TableRecord
type.
static func hasMany<Pivot, Target>(_ destination: Target.RowDecoder.Type, through pivot: Pivot, using target: Target, key: String? = nil) -> HasManyThroughAssociation<Self, Target.RowDecoder> where Self == Pivot.OriginRowDecoder, Pivot : Association, Target : Association, Pivot.RowDecoder == Target.OriginRowDecoder
Creates a HasManyThroughAssociation
between Self
and the destination TableRecord
type.
static func hasOne<Destination>(_ destination: Table<Destination>, key: String? = nil, using foreignKey: ForeignKey? = nil) -> HasOneAssociation<Self, Destination>
Creates a HasOneAssociation
between Self
and the destination Table
.
static func hasOne<Destination>(_ destination: Destination.Type, key: String? = nil, using foreignKey: ForeignKey? = nil) -> HasOneAssociation<Self, Destination> where Destination : TableRecord
Creates a HasOneAssociation
between Self
and the destination TableRecord
type.
static func hasOne<Pivot, Target>(_ destination: Target.RowDecoder.Type, through pivot: Pivot, using target: Target, key: String? = nil) -> HasOneThroughAssociation<Self, Target.RowDecoder> where Self == Pivot.OriginRowDecoder, Pivot : AssociationToOne, Target : AssociationToOne, Pivot.RowDecoder == Target.OriginRowDecoder
Creates a HasOneThroughAssociation
between Self
and the destination TableRecord
type.
static func numberOfSelectedColumns(_ db: Database) throws -> Int
Returns the number of selected columns.
static func recordNotFound(_ db: Database, key: some DatabaseValueConvertible) -> any Error
Returns an error for a record that does not exist in the database.
static func recordNotFound(key: [String : (any DatabaseValueConvertible)?]) -> RecordError
Returns an error for a record that does not exist in the database.
@discardableResult static func updateAll(_ db: Database, onConflict conflictResolution: Database.ConflictResolution? = nil, _ assignments: ColumnAssignment...) throws -> Int
Updates all records, and returns the number of updated records.
@discardableResult static func updateAll(_ db: Database, onConflict conflictResolution: Database.ConflictResolution? = nil, _ assignments: [ColumnAssignment]) throws -> Int
Updates all records, and returns the number of updated records.