Restore TableRecord.selectionSQL in the form of SQL interpolation

This commit is contained in:
Gwendal Roué committed 2020-04-30 19:33:33 +02:00
1 parent df2cc0af36
commit 443d44cc7a
3 files changed
+42 -9

No files matched your search

@@ -17,6 +17,22 @@ extension SQLInterpolation {
appendInterpolation(type(of: record))
}
/// Appends the selection of the record type.
///
/// // SELECT * FROM player
/// let player: Player = ...
/// let request: SQLRequest<Player> = "SELECT \(columnsOf: Player.self) FROM player"
///
/// // SELECT p.* FROM player p
/// let player: Player = ...
/// let request: SQLRequest<Player> = "SELECT \(columnsOf: Player.self, tableAlias: "p") FROM player p"
public mutating func appendInterpolation<T: TableRecord>(columnsOf record: T.Type, tableAlias: String? = nil) {
let alias = TableAlias(name: tableAlias ?? T.databaseTableName)
elements.append(contentsOf: T.databaseSelection
.map { CollectionOfOne(.selectable($0.qualifiedSelectable(with: alias))) }
.joined(separator: CollectionOfOne(.sql(","))))
}
/// Appends the selectable SQL.
///
/// // SELECT * FROM player