Inline documentation for annotated(withOptional:), annotated(withRequired:)

This commit is contained in:
Gwendal Roué committed 2021-12-05 15:04:44 +01:00
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()
+68 -2
View File
@@ -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