mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-28 04:24:20 +00:00
Remove QueryInterfaceRequest.exists()
This commit is contained in:
1 parent
6629ec48a3
commit
b3d731b040
5 files changed
+1
-90
No files matched your search
@@ -6,6 +6,7 @@ Release Notes
|
||||
**Breaking Changes**
|
||||
|
||||
- `DatabaseCoder` has been removed.
|
||||
- `QueryInterfaceRequest.exists` has been removed.
|
||||
|
||||
|
||||
## 0.110.0
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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)`
|
||||
|
||||
[]((#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:
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
Reference in new issue
Block a user