From b3d731b040b934bcfceed36845c125b16c1cdf44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sun, 4 Jun 2017 16:18:17 +0200 Subject: [PATCH] Remove QueryInterfaceRequest.exists() --- CHANGELOG.md | 1 + .../SQLExpression+QueryInterface.swift | 53 ------------------- GRDB/QueryInterface/SQLSelectQuery.swift | 13 ----- README.md | 13 ----- .../QueryInterfaceExpressionsTests.swift | 11 ---- 5 files changed, 1 insertion(+), 90 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8630435ad..8c13c2c92 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ Release Notes **Breaking Changes** - `DatabaseCoder` has been removed. +- `QueryInterfaceRequest.exists` has been removed. ## 0.110.0 diff --git a/GRDB/QueryInterface/SQLExpression+QueryInterface.swift b/GRDB/QueryInterface/SQLExpression+QueryInterface.swift index cae697c93..cc9eedf57 100644 --- a/GRDB/QueryInterface/SQLExpression+QueryInterface.swift +++ b/GRDB/QueryInterface/SQLExpression+QueryInterface.swift @@ -294,59 +294,6 @@ struct SQLExpressionContains : SQLExpression { } } -// MARK: - SQLExpressionExists - -/// This type is an implementation detail of the query interface. -/// Do not use it directly. -/// -/// See https://github.com/groue/GRDB.swift/#the-query-interface -/// -/// # Low Level Query Interface -/// -/// SQLExpressionExists is an expression that checks if a subquery would return -/// rows or not with the `EXISTS` operator. -public struct SQLExpressionExists : SQLExpression { - /// The query - public let query: SQLSelectQuery - - /// If true, uses `NOT EXISTS` instead of `EXISTS` operator - public let isNegated: Bool - - /// Creates an expression that checks if a subquery would return rows - /// or not with the `EXISTS` operator. - public init(_ query: SQLSelectQuery, negated: Bool = false) { - self.query = query - self.isNegated = negated - } - - /// This function is an implementation detail of the query interface. - /// Do not use it directly. - /// - /// See https://github.com/groue/GRDB.swift/#the-query-interface - /// - /// # Low Level Query Interface - /// - /// See SQLExpression.expressionSQL(_:arguments:) - public func expressionSQL(_ arguments: inout StatementArguments?) -> String { - return "(" + - (isNegated ? "NOT EXISTS (" : "EXISTS (") + - query.selectQuerySQL(&arguments) - + "))" - } - - /// This property is an implementation detail of the query interface. - /// Do not use it directly. - /// - /// See https://github.com/groue/GRDB.swift/#the-query-interface - /// - /// # Low Level Query Interface - /// - /// See SQLExpression.negated - public var negated: SQLExpression { - return SQLExpressionExists(query, negated: !isNegated) - } -} - // MARK: - SQLExpressionBetween /// SQLExpressionBetween is an expression that checks if a values is included diff --git a/GRDB/QueryInterface/SQLSelectQuery.swift b/GRDB/QueryInterface/SQLSelectQuery.swift index e8a3b1a8f..41f57ca4f 100644 --- a/GRDB/QueryInterface/SQLSelectQuery.swift +++ b/GRDB/QueryInterface/SQLSelectQuery.swift @@ -27,19 +27,6 @@ public protocol SQLSelectQuery : Request, SQLCollection { func selectQuerySQL(_ arguments: inout StatementArguments?) -> String } -extension SQLSelectQuery { - - /// Returns an SQL expression that checks whether the receiver, as a - /// subquery, returns any row. - /// - /// - /// let request = Person.all() - /// request.exists() // EXISTS (SELECT * FROM persons) - public func exists() -> SQLExpression { - return SQLExpressionExists(self) - } -} - // MARK: - SQLCollection adoption diff --git a/README.md b/README.md index d90b271d4..743327e52 100644 --- a/README.md +++ b/README.md @@ -2937,19 +2937,6 @@ Feed [requests](#requests) with SQL expressions built from your Swift code: Event.filter(verifiedUserIds.contains(userIdColumn)) ``` -- `EXISTS (subquery)`, `NOT EXISTS (subquery)` - - [![Experimental](https://cdn.rawgit.com/groue/GRDB.swift/GRDB1/Documentation/images/experimental.svg)]((#what-are-experimental-features)) - - To check is a subquery would return any row, use the `exists` property on another request: - - ```swift - // SELECT * FROM persons - // WHERE EXISTS (SELECT * FROM books - // WHERE books.ownerId = persons.id) - Person.filter(Book.filter(sql: "books.ownerId = persons.id").exists) - ``` - - `LIKE` The SQLite LIKE operator is available as the `like` method: diff --git a/Tests/GRDBTests/QueryInterfaceExpressionsTests.swift b/Tests/GRDBTests/QueryInterfaceExpressionsTests.swift index bc7d64b71..227a8d541 100644 --- a/Tests/GRDBTests/QueryInterfaceExpressionsTests.swift +++ b/Tests/GRDBTests/QueryInterfaceExpressionsTests.swift @@ -677,17 +677,6 @@ class QueryInterfaceExpressionsTests: GRDBTestCase { "SELECT * FROM \"readers\" WHERE (\"age\" IS NOT \"age\")") } - func testExists() throws { - let dbQueue = try makeDatabaseQueue() - - XCTAssertEqual( - sql(dbQueue, tableRequest.filter(tableRequest.exists())), - "SELECT * FROM \"readers\" WHERE (EXISTS (SELECT * FROM \"readers\"))") - XCTAssertEqual( - sql(dbQueue, tableRequest.filter(!tableRequest.exists())), - "SELECT * FROM \"readers\" WHERE (NOT EXISTS (SELECT * FROM \"readers\"))") - } - func testLogicalOperators() throws { let dbQueue = try makeDatabaseQueue()