mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-28 04:24:20 +00:00
Inline documentation for annotated(withOptional:), annotated(withRequired:)
This commit is contained in:
1 parent
e1dc24ac93
commit
9df0f4cdbd
3 files changed
+188
-6
No files matched your search
@@ -704,7 +704,36 @@ extension JoinableRequest {
|
||||
}
|
||||
|
||||
extension JoinableRequest where Self: SelectionRequest {
|
||||
#warning("TODO: document")
|
||||
/// Creates a request which appends *columns of an associated record* to
|
||||
/// the current selection.
|
||||
///
|
||||
/// // SELECT player.*, team.color
|
||||
/// // FROM player LEFT JOIN team ...
|
||||
/// let teamColor = Player.team.select(Column("color"))
|
||||
/// let request = Player.all().annotated(withOptional: teamColor)
|
||||
///
|
||||
/// This method performs the same SQL request as `including(optional:)`.
|
||||
/// The difference is in the shape of Decodable records that decode such
|
||||
/// a request: the associated columns can be decoded at the same level as
|
||||
/// the main record:
|
||||
///
|
||||
/// struct PlayerWithTeamColor: FetchableRecord, Decodable {
|
||||
/// var player: Player
|
||||
/// var color: String?
|
||||
/// }
|
||||
/// let players = try dbQueue.read { db in
|
||||
/// try request
|
||||
/// .asRequest(of: PlayerWithTeamColor.self)
|
||||
/// .fetchAll(db)
|
||||
/// }
|
||||
///
|
||||
/// Note: this is a convenience method. You can build the same request with
|
||||
/// `TableAlias`, `annotated(with:)`, and `joining(optional:)`:
|
||||
///
|
||||
/// let teamAlias = TableAlias()
|
||||
/// let request = Player.all()
|
||||
/// .annotated(with: teamAlias[Column("color")])
|
||||
/// .joining(optional: Player.team.aliased(teamAlias))
|
||||
public func annotated<A: Association>(withOptional association: A) -> Self where A.OriginRowDecoder == RowDecoder {
|
||||
let alias = TableAlias()
|
||||
let selection = association._sqlAssociation.destination.relation.selectionPromise
|
||||
@@ -717,7 +746,36 @@ extension JoinableRequest where Self: SelectionRequest {
|
||||
})
|
||||
}
|
||||
|
||||
#warning("TODO: document")
|
||||
/// Creates a request which appends *columns of an associated record* to
|
||||
/// the current selection.
|
||||
///
|
||||
/// // SELECT player.*, team.color
|
||||
/// // FROM player JOIN team ...
|
||||
/// let teamColor = Player.team.select(Column("color"))
|
||||
/// let request = Player.all().annotated(withRequired: teamColor)
|
||||
///
|
||||
/// This method performs the same SQL request as `including(required:)`.
|
||||
/// The difference is in the shape of Decodable records that decode such
|
||||
/// a request: the associated columns can be decoded at the same level as
|
||||
/// the main record:
|
||||
///
|
||||
/// struct PlayerWithTeamColor: FetchableRecord, Decodable {
|
||||
/// var player: Player
|
||||
/// var color: String
|
||||
/// }
|
||||
/// let players = try dbQueue.read { db in
|
||||
/// try request
|
||||
/// .asRequest(of: PlayerWithTeamColor.self)
|
||||
/// .fetchAll(db)
|
||||
/// }
|
||||
///
|
||||
/// Note: this is a convenience method. You can build the same request with
|
||||
/// `TableAlias`, `annotated(with:)`, and `joining(required:)`:
|
||||
///
|
||||
/// let teamAlias = TableAlias()
|
||||
/// let request = Player.all()
|
||||
/// .annotated(with: teamAlias[Column("color")])
|
||||
/// .joining(required: Player.team.aliased(teamAlias))
|
||||
public func annotated<A: Association>(withRequired association: A) -> Self where A.OriginRowDecoder == RowDecoder {
|
||||
let selection = association._sqlAssociation.destination.relation.selectionPromise
|
||||
let alias = TableAlias()
|
||||
|
||||
@@ -1187,7 +1187,40 @@ extension Table {
|
||||
all().joining(required: association)
|
||||
}
|
||||
|
||||
#warning("TODO: document")
|
||||
/// Creates a request which appends *columns of an associated record* to
|
||||
/// the columns of the table.
|
||||
///
|
||||
/// let playerTable = Table("player")
|
||||
/// let teamTable = Table("team")
|
||||
/// let playerTeam = playerTable.belongsTo(teamTable)
|
||||
///
|
||||
/// // SELECT player.*, team.color
|
||||
/// // FROM player LEFT JOIN team ...
|
||||
/// let teamColor = playerTeam.select(Column("color")
|
||||
/// let request = playerTable.annotated(withOptional: teamColor))
|
||||
///
|
||||
/// This method performs the same SQL request as `including(optional:)`.
|
||||
/// The difference is in the shape of Decodable records that decode such
|
||||
/// a request: the associated columns can be decoded at the same level as
|
||||
/// the main record:
|
||||
///
|
||||
/// struct PlayerWithTeamColor: FetchableRecord, Decodable {
|
||||
/// var player: Player
|
||||
/// var color: String?
|
||||
/// }
|
||||
/// let players = try dbQueue.read { db in
|
||||
/// try request
|
||||
/// .asRequest(of: PlayerWithTeamColor.self)
|
||||
/// .fetchAll(db)
|
||||
/// }
|
||||
///
|
||||
/// Note: this is a convenience method. You can build the same request with
|
||||
/// `TableAlias`, `annotated(with:)`, and `joining(optional:)`:
|
||||
///
|
||||
/// let teamAlias = TableAlias()
|
||||
/// let request = playerTable
|
||||
/// .annotated(with: teamAlias[Column("color")])
|
||||
/// .joining(optional: playerTeam.aliased(teamAlias))
|
||||
public func annotated<A: Association>(withOptional association: A)
|
||||
-> QueryInterfaceRequest<RowDecoder>
|
||||
where A.OriginRowDecoder == RowDecoder
|
||||
@@ -1195,7 +1228,40 @@ extension Table {
|
||||
all().annotated(withOptional: association)
|
||||
}
|
||||
|
||||
#warning("TODO: document")
|
||||
/// Creates a request which appends *columns of an associated record* to
|
||||
/// the columns of the table.
|
||||
///
|
||||
/// let playerTable = Table("player")
|
||||
/// let teamTable = Table("team")
|
||||
/// let playerTeam = playerTable.belongsTo(teamTable)
|
||||
///
|
||||
/// // SELECT player.*, team.color
|
||||
/// // FROM player JOIN team ...
|
||||
/// let teamColor = playerTeam.select(Column("color")
|
||||
/// let request = playerTable.annotated(withRequired: teamColor))
|
||||
///
|
||||
/// This method performs the same SQL request as `including(required:)`.
|
||||
/// The difference is in the shape of Decodable records that decode such
|
||||
/// a request: the associated columns can be decoded at the same level as
|
||||
/// the main record:
|
||||
///
|
||||
/// struct PlayerWithTeamColor: FetchableRecord, Decodable {
|
||||
/// var player: Player
|
||||
/// var color: String
|
||||
/// }
|
||||
/// let players = try dbQueue.read { db in
|
||||
/// try request
|
||||
/// .asRequest(of: PlayerWithTeamColor.self)
|
||||
/// .fetchAll(db)
|
||||
/// }
|
||||
///
|
||||
/// Note: this is a convenience method. You can build the same request with
|
||||
/// `TableAlias`, `annotated(with:)`, and `joining(required:)`:
|
||||
///
|
||||
/// let teamAlias = TableAlias()
|
||||
/// let request = playerTable
|
||||
/// .annotated(with: teamAlias[Column("color")])
|
||||
/// .joining(required: playerTeam.aliased(teamAlias))
|
||||
public func annotated<A: Association>(withRequired association: A)
|
||||
-> QueryInterfaceRequest<RowDecoder>
|
||||
where A.OriginRowDecoder == RowDecoder
|
||||
|
||||
@@ -621,7 +621,36 @@ extension TableRecord {
|
||||
all().joining(required: association)
|
||||
}
|
||||
|
||||
#warning("TODO: document")
|
||||
/// Creates a request which appends *columns of an associated record* to
|
||||
/// the selection.
|
||||
///
|
||||
/// // SELECT player.*, team.color
|
||||
/// // FROM player LEFT JOIN team ...
|
||||
/// let teamColor = Player.team.select(Column("color"))
|
||||
/// let request = Player.annotated(withOptional: teamColor)
|
||||
///
|
||||
/// This method performs the same SQL request as `including(optional:)`.
|
||||
/// The difference is in the shape of Decodable records that decode such
|
||||
/// a request: the associated columns can be decoded at the same level as
|
||||
/// the main record:
|
||||
///
|
||||
/// struct PlayerWithTeamColor: FetchableRecord, Decodable {
|
||||
/// var player: Player
|
||||
/// var color: String?
|
||||
/// }
|
||||
/// let players = try dbQueue.read { db in
|
||||
/// try request
|
||||
/// .asRequest(of: PlayerWithTeamColor.self)
|
||||
/// .fetchAll(db)
|
||||
/// }
|
||||
///
|
||||
/// Note: this is a convenience method. You can build the same request with
|
||||
/// `TableAlias`, `annotated(with:)`, and `joining(optional:)`:
|
||||
///
|
||||
/// let teamAlias = TableAlias()
|
||||
/// let request = Player
|
||||
/// .annotated(with: teamAlias[Column("color")])
|
||||
/// .joining(optional: Player.team.aliased(teamAlias))
|
||||
public static func annotated<A: Association>(withOptional association: A)
|
||||
-> QueryInterfaceRequest<Self>
|
||||
where A.OriginRowDecoder == Self
|
||||
@@ -629,7 +658,36 @@ extension TableRecord {
|
||||
all().annotated(withOptional: association)
|
||||
}
|
||||
|
||||
#warning("TODO: document")
|
||||
/// Creates a request which appends *columns of an associated record* to
|
||||
/// the selection.
|
||||
///
|
||||
/// // SELECT player.*, team.color
|
||||
/// // FROM player JOIN team ...
|
||||
/// let teamColor = Player.team.select(Column("color"))
|
||||
/// let request = Player.annotated(withRequired: teamColor)
|
||||
///
|
||||
/// This method performs the same SQL request as `including(required:)`.
|
||||
/// The difference is in the shape of Decodable records that decode such
|
||||
/// a request: the associated columns can be decoded at the same level as
|
||||
/// the main record:
|
||||
///
|
||||
/// struct PlayerWithTeamColor: FetchableRecord, Decodable {
|
||||
/// var player: Player
|
||||
/// var color: String
|
||||
/// }
|
||||
/// let players = try dbQueue.read { db in
|
||||
/// try request
|
||||
/// .asRequest(of: PlayerWithTeamColor.self)
|
||||
/// .fetchAll(db)
|
||||
/// }
|
||||
///
|
||||
/// Note: this is a convenience method. You can build the same request with
|
||||
/// `TableAlias`, `annotated(with:)`, and `joining(required:)`:
|
||||
///
|
||||
/// let teamAlias = TableAlias()
|
||||
/// let request = Player
|
||||
/// .annotated(with: teamAlias[Column("color")])
|
||||
/// .joining(required: Player.team.aliased(teamAlias))
|
||||
public static func annotated<A: Association>(withRequired association: A)
|
||||
-> QueryInterfaceRequest<Self>
|
||||
where A.OriginRowDecoder == Self
|
||||
|
||||
Reference in new issue
Block a user