Fix subqueries semantics

This commit is contained in:
Gwendal Roué committed 2020-04-30 08:19:00 +02:00
1 parent 026e5b288f
commit 1d89d184fd
5 files changed
+23 -36

No files matched your search

@@ -437,14 +437,6 @@ extension QueryInterfaceRequest: SQLSpecificExpressible {
}
}
// Support for `SQLLiteral("SELECT ... IN (\(request))")`
extension QueryInterfaceRequest: SQLRequestExpressible {
/// :nodoc
public func requestSQL(_ context: SQLGenerationContext) throws -> String {
try SQLQueryGenerator(query: query).sql(context)
}
}
extension QueryInterfaceRequest: TableRequest {
/// :nodoc:
public var databaseTableName: String {
@@ -52,19 +52,6 @@ public protocol SQLSpecificExpressible: SQLExpressible {
// - ==(SQLSpecificExpressible, SQLSpecificExpressible)
}
// MARK: - SQLRequestExpressible
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
///
/// A protocol for request types that are used as an SQL expression.
///
/// :nodoc:
public protocol SQLRequestExpressible: SQLSpecificExpressible {
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
/// :nodoc:
func requestSQL(_ context: SQLGenerationContext) throws -> String
}
// MARK: - SQLExpressible & SQLOrderingTerm
extension SQLExpressible where Self: SQLOrderingTerm {
@@ -154,7 +154,20 @@ extension SQLInterpolation {
/// let request: SQLRequest<Player> = """
/// SELECT * FROM player WHERE score = (\(subQuery))
/// """
public mutating func appendInterpolation(_ request: SQLRequestExpressible) {
elements.append(.custom(request.requestSQL))
public mutating func appendInterpolation<RowDecoder>(_ request: SQLRequest<RowDecoder>) {
elements.append(.subquery(request.sqlLiteral.sql))
}
/// Appends the request SQL (not wrapped inside parentheses).
///
/// // SELECT name FROM player WHERE score = (SELECT MAX(score) FROM player)
/// let subQuery = Player.select(max(Column("score")))
/// let request: SQLRequest<Player> = """
/// SELECT * FROM player WHERE score = (\(subQuery))
/// """
public mutating func appendInterpolation<RowDecoder>(_ request: QueryInterfaceRequest<RowDecoder>) {
elements.append(.subquery { context in
try SQLQueryGenerator(query: request.query).sql(context)
})
}
}