ColumnExpression.detached

This commit is contained in:
Gwendal Roué committed 2022-01-07 10:07:15 +01:00
1 parent 536ad2ebff
commit e799c8534e
2 files changed
+66

No files matched your search

+22
View File
@@ -28,6 +28,28 @@ extension ColumnExpression {
public var sqlExpression: SQLExpression {
.column(name)
}
/// Returns a "detached column", which is never qualified with any table
/// name in the SQL generated by the query interface. A detached column
/// allows you to refer to an aliased expression (`expression AS alias`).
///
/// For example, see how `Column("total").detached` makes it possible to
/// sort this query, when a raw `Column("total")` could not:
///
/// // SELECT player.*,
/// // (player.score + player.bonus) AS total,
/// // team.*
/// // FROM player
/// // JOIN team ON team.id = player.teamID
/// // ORDER BY total, player.name
/// // ~~~~~
/// let request = Player
/// .annotated(with: (Column("score") + Column("bonus")).forKey("total"))
/// .including(required: Book.team)
/// .order(Column("total").detached, Column("name"))
public var detached: SQLExpression {
SQL(sql: name.quotedDatabaseIdentifier).sqlExpression
}
}
#if compiler(>=5.5)