mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-28 04:24:20 +00:00
Restore TableRecord.selectionSQL in the form of SQL interpolation
This commit is contained in:
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
|
||||
|
||||
Reference in new issue
Block a user