mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-27 04:14:21 +00:00
FetchRequest.makePreparedRequest
This commit is contained in:
1 parent
65de31a335
commit
e40e37bd04
13 files changed
+48
-51
No files matched your search
+3
-5
@@ -131,8 +131,6 @@ The [ValueObservation Error Handling](README.md#valueobservation-error-handling)
|
||||
}
|
||||
```
|
||||
|
||||
The core FetchRequest preparation method is now `preparedRequest(_:forSingleResult:)`. The former core method `prepare(_:forSingleResult:)` will remain a requirement of the FetchRequest protocol until GRDB 5 due to semantic versioning constraints. Both methods are provided with a default implementation which makes each one depend on the other: this creates an infinite loop unless you provide at least one of them. If you have a choice, prefer `preparedRequest(_:forSingleResult:)`.
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
@@ -158,7 +156,7 @@ The core FetchRequest preparation method is now `preparedRequest(_:forSingleResu
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary>Miscellaneous changes</summary>
|
||||
<summary>FetchRequest changes</summary>
|
||||
|
||||
```diff
|
||||
+struct PreparedRequest {
|
||||
@@ -170,11 +168,11 @@ The core FetchRequest preparation method is now `preparedRequest(_:forSingleResu
|
||||
protocol FetchRequest {
|
||||
+ // deprecated
|
||||
func prepare(_ db: Database, forSingleResult singleResult: Bool) throws -> (SelectStatement, RowAdapter?)
|
||||
+ func preparedRequest(_ db: Database, forSingleResult singleResult: Bool) throws -> PreparedRequest
|
||||
+ func makePreparedRequest(_ db: Database, forSingleResult singleResult: Bool) throws -> PreparedRequest
|
||||
}
|
||||
```
|
||||
|
||||
The core FetchRequest preparation method is now `preparedRequest(_:forSingleResult:)`. The former core method `prepare(_:forSingleResult:)` will remain a requirement of the FetchRequest protocol until GRDB 5 due to semantic versioning constraints. Both methods are provided with a default implementation which makes each one depend on the other: this creates an infinite loop unless you provide at least one of them. If you have a choice, prefer `preparedRequest(_:forSingleResult:)`.
|
||||
The core FetchRequest preparation method is now `makePreparedRequest(_:forSingleResult:)`. The former core method `prepare(_:forSingleResult:)` will remain a requirement of the FetchRequest protocol until GRDB 5 due to semantic versioning constraints. Both methods are provided with a default implementation which makes each one depend on the other: this creates an infinite loop unless you provide at least one of them. If you have a choice, prefer `makePreparedRequest(_:forSingleResult:)`.
|
||||
|
||||
</details>
|
||||
|
||||
|
||||
@@ -306,7 +306,7 @@ extension DatabaseValueConvertible {
|
||||
/// - returns: A cursor over fetched values.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public static func fetchCursor<R: FetchRequest>(_ db: Database, _ request: R) throws -> DatabaseValueCursor<Self> {
|
||||
let request = try request.preparedRequest(db, forSingleResult: false)
|
||||
let request = try request.makePreparedRequest(db, forSingleResult: false)
|
||||
return try fetchCursor(request.statement, adapter: request.adapter)
|
||||
}
|
||||
|
||||
@@ -321,7 +321,7 @@ extension DatabaseValueConvertible {
|
||||
/// - returns: An array.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public static func fetchAll<R: FetchRequest>(_ db: Database, _ request: R) throws -> [Self] {
|
||||
let request = try request.preparedRequest(db, forSingleResult: false)
|
||||
let request = try request.makePreparedRequest(db, forSingleResult: false)
|
||||
return try fetchAll(request.statement, adapter: request.adapter)
|
||||
}
|
||||
|
||||
@@ -339,7 +339,7 @@ extension DatabaseValueConvertible {
|
||||
/// - returns: An optional value.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public static func fetchOne<R: FetchRequest>(_ db: Database, _ request: R) throws -> Self? {
|
||||
let request = try request.preparedRequest(db, forSingleResult: true)
|
||||
let request = try request.makePreparedRequest(db, forSingleResult: true)
|
||||
return try fetchOne(request.statement, adapter: request.adapter)
|
||||
}
|
||||
}
|
||||
@@ -516,7 +516,7 @@ extension Optional where Wrapped: DatabaseValueConvertible {
|
||||
/// - returns: A cursor over fetched optional values.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public static func fetchCursor<R: FetchRequest>(_ db: Database, _ request: R) throws -> NullableDatabaseValueCursor<Wrapped> {
|
||||
let request = try request.preparedRequest(db, forSingleResult: false)
|
||||
let request = try request.makePreparedRequest(db, forSingleResult: false)
|
||||
return try fetchCursor(request.statement, adapter: request.adapter)
|
||||
}
|
||||
|
||||
@@ -531,7 +531,7 @@ extension Optional where Wrapped: DatabaseValueConvertible {
|
||||
/// - returns: An array of optional values.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public static func fetchAll<R: FetchRequest>(_ db: Database, _ request: R) throws -> [Wrapped?] {
|
||||
let request = try request.preparedRequest(db, forSingleResult: false)
|
||||
let request = try request.makePreparedRequest(db, forSingleResult: false)
|
||||
return try fetchAll(request.statement, adapter: request.adapter)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ public protocol FetchRequest: DatabaseRegionConvertible {
|
||||
|
||||
// TODO: remove when we remove the deprecated prepare(_:forSingleResult:) method
|
||||
/// This method is deprecated. Use
|
||||
/// `preparedRequest(_:forSingleResult:)` instead.
|
||||
/// `makePreparedRequest(_:forSingleResult:)` instead.
|
||||
///
|
||||
/// Returns a tuple that contains a prepared statement that is ready to be
|
||||
/// executed, and an eventual row adapter.
|
||||
@@ -63,15 +63,14 @@ public protocol FetchRequest: DatabaseRegionConvertible {
|
||||
/// - returns: A prepared statement and an eventual row adapter.
|
||||
func prepare(_ db: Database, forSingleResult singleResult: Bool) throws -> (SelectStatement, RowAdapter?)
|
||||
|
||||
/// Returns a PreparedRequest made of a prepared statement that is ready to
|
||||
/// be executed, and an eventual row adapter.
|
||||
/// Returns a PreparedRequest that is ready to be executed.
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
/// - parameter singleResult: A hint that a single result row will be
|
||||
/// consumed. Implementations can optionally use this to optimize the
|
||||
/// prepared statement.
|
||||
/// - returns: A prepared request.
|
||||
func preparedRequest(_ db: Database, forSingleResult singleResult: Bool) throws -> PreparedRequest
|
||||
func makePreparedRequest(_ db: Database, forSingleResult singleResult: Bool) throws -> PreparedRequest
|
||||
|
||||
/// Returns the number of rows fetched by the request.
|
||||
///
|
||||
@@ -100,7 +99,7 @@ extension FetchRequest {
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
public func fetchCount(_ db: Database) throws -> Int {
|
||||
let request = try preparedRequest(db, forSingleResult: false)
|
||||
let request = try makePreparedRequest(db, forSingleResult: false)
|
||||
let sql = "SELECT COUNT(*) FROM (\(request.statement.sql))"
|
||||
return try Int.fetchOne(db, sql: sql, arguments: request.statement.arguments)!
|
||||
}
|
||||
@@ -112,14 +111,14 @@ extension FetchRequest {
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
public func databaseRegion(_ db: Database) throws -> DatabaseRegion {
|
||||
let request = try preparedRequest(db, forSingleResult: false)
|
||||
let request = try makePreparedRequest(db, forSingleResult: false)
|
||||
return request.statement.databaseRegion
|
||||
}
|
||||
|
||||
// Support for legacy requests which only define prepare(_:forSingleResult:)
|
||||
// TODO: remove when we remove the deprecated prepare(_:forSingleResult:) method
|
||||
/// :nodoc:
|
||||
public func preparedRequest(_ db: Database, forSingleResult singleResult: Bool) throws -> PreparedRequest {
|
||||
public func makePreparedRequest(_ db: Database, forSingleResult singleResult: Bool) throws -> PreparedRequest {
|
||||
let (statement, adapter) = try prepare(db, forSingleResult: singleResult)
|
||||
return PreparedRequest(statement: statement, adapter: adapter)
|
||||
}
|
||||
@@ -127,7 +126,7 @@ extension FetchRequest {
|
||||
// TODO: remove when we remove the deprecated prepare(_:forSingleResult:) method
|
||||
/// :nodoc:
|
||||
public func prepare(_ db: Database, forSingleResult singleResult: Bool) throws -> (SelectStatement, RowAdapter?) {
|
||||
let request = try preparedRequest(db, forSingleResult: singleResult)
|
||||
let request = try makePreparedRequest(db, forSingleResult: singleResult)
|
||||
return (request.statement, request.adapter)
|
||||
}
|
||||
}
|
||||
@@ -149,8 +148,8 @@ public struct AdaptedFetchRequest<Base: FetchRequest> : FetchRequest {
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
public func preparedRequest(_ db: Database, forSingleResult singleResult: Bool) throws -> PreparedRequest {
|
||||
var request = try base.preparedRequest(db, forSingleResult: singleResult)
|
||||
public func makePreparedRequest(_ db: Database, forSingleResult singleResult: Bool) throws -> PreparedRequest {
|
||||
var request = try base.makePreparedRequest(db, forSingleResult: singleResult)
|
||||
if let baseAdapter = request.adapter {
|
||||
request.adapter = try ChainedAdapter(first: baseAdapter, second: adapter(db))
|
||||
} else {
|
||||
@@ -185,7 +184,7 @@ public struct AnyFetchRequest<T> : FetchRequest {
|
||||
|
||||
/// Creates a request that wraps and forwards operations to `request`.
|
||||
public init<Request: FetchRequest>(_ request: Request) {
|
||||
_preparedRequest = request.preparedRequest
|
||||
_preparedRequest = request.makePreparedRequest
|
||||
_fetchCount = request.fetchCount
|
||||
_databaseRegion = request.databaseRegion
|
||||
}
|
||||
@@ -212,7 +211,7 @@ public struct AnyFetchRequest<T> : FetchRequest {
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
public func preparedRequest(_ db: Database, forSingleResult singleResult: Bool) throws -> PreparedRequest {
|
||||
public func makePreparedRequest(_ db: Database, forSingleResult singleResult: Bool) throws -> PreparedRequest {
|
||||
return try _preparedRequest(db, singleResult)
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -980,7 +980,7 @@ extension Row {
|
||||
/// - returns: A cursor over fetched rows.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public static func fetchCursor<R: FetchRequest>(_ db: Database, _ request: R) throws -> RowCursor {
|
||||
let request = try request.preparedRequest(db, forSingleResult: false)
|
||||
let request = try request.makePreparedRequest(db, forSingleResult: false)
|
||||
precondition(request.supplementaryFetch == nil, "Not implemented: fetchCursor with supplementary fetch")
|
||||
return try fetchCursor(request.statement, adapter: request.adapter)
|
||||
}
|
||||
@@ -996,7 +996,7 @@ extension Row {
|
||||
/// - returns: An array of rows.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public static func fetchAll<R: FetchRequest>(_ db: Database, _ request: R) throws -> [Row] {
|
||||
let request = try request.preparedRequest(db, forSingleResult: false)
|
||||
let request = try request.makePreparedRequest(db, forSingleResult: false)
|
||||
let rows = try fetchAll(request.statement, adapter: request.adapter)
|
||||
try request.supplementaryFetch?(rows)
|
||||
return rows
|
||||
@@ -1013,7 +1013,7 @@ extension Row {
|
||||
/// - returns: An optional row.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public static func fetchOne<R: FetchRequest>(_ db: Database, _ request: R) throws -> Row? {
|
||||
let request = try request.preparedRequest(db, forSingleResult: true)
|
||||
let request = try request.makePreparedRequest(db, forSingleResult: true)
|
||||
guard let row = try fetchOne(request.statement, adapter: request.adapter) else {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ public struct SQLRequest<T> : FetchRequest {
|
||||
/// prepared statement.
|
||||
/// - returns: An SQLRequest
|
||||
public init<Request: FetchRequest>(_ db: Database, request: Request, cached: Bool = false) throws where Request.RowDecoder == RowDecoder {
|
||||
let request = try request.preparedRequest(db, forSingleResult: false)
|
||||
let request = try request.makePreparedRequest(db, forSingleResult: false)
|
||||
self.init(
|
||||
literal: SQLLiteral(sql: request.statement.sql, arguments: request.statement.arguments),
|
||||
adapter: request.adapter,
|
||||
@@ -131,7 +131,7 @@ public struct SQLRequest<T> : FetchRequest {
|
||||
/// - parameter singleResult: SQLRequest disregards this hint.
|
||||
///
|
||||
/// :nodoc:
|
||||
public func preparedRequest(_ db: Database, forSingleResult singleResult: Bool) throws -> PreparedRequest {
|
||||
public func makePreparedRequest(_ db: Database, forSingleResult singleResult: Bool) throws -> PreparedRequest {
|
||||
let statement: SelectStatement
|
||||
switch cache {
|
||||
case .none:
|
||||
|
||||
@@ -305,7 +305,7 @@ extension DatabaseValueConvertible where Self: StatementColumnConvertible {
|
||||
/// - returns: A cursor over fetched values.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public static func fetchCursor<R: FetchRequest>(_ db: Database, _ request: R) throws -> FastDatabaseValueCursor<Self> {
|
||||
let request = try request.preparedRequest(db, forSingleResult: false)
|
||||
let request = try request.makePreparedRequest(db, forSingleResult: false)
|
||||
return try fetchCursor(request.statement, adapter: request.adapter)
|
||||
}
|
||||
|
||||
@@ -320,7 +320,7 @@ extension DatabaseValueConvertible where Self: StatementColumnConvertible {
|
||||
/// - returns: An array of values.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public static func fetchAll<R: FetchRequest>(_ db: Database, _ request: R) throws -> [Self] {
|
||||
let request = try request.preparedRequest(db, forSingleResult: false)
|
||||
let request = try request.makePreparedRequest(db, forSingleResult: false)
|
||||
return try fetchAll(request.statement, adapter: request.adapter)
|
||||
}
|
||||
|
||||
@@ -335,7 +335,7 @@ extension DatabaseValueConvertible where Self: StatementColumnConvertible {
|
||||
/// - returns: An optional value.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public static func fetchOne<R: FetchRequest>(_ db: Database, _ request: R) throws -> Self? {
|
||||
let request = try request.preparedRequest(db, forSingleResult: true)
|
||||
let request = try request.makePreparedRequest(db, forSingleResult: true)
|
||||
return try fetchOne(request.statement, adapter: request.adapter)
|
||||
}
|
||||
}
|
||||
@@ -512,7 +512,7 @@ extension Optional where Wrapped: DatabaseValueConvertible & StatementColumnConv
|
||||
/// - returns: A cursor over fetched optional values.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public static func fetchCursor<R: FetchRequest>(_ db: Database, _ request: R) throws -> FastNullableDatabaseValueCursor<Wrapped> {
|
||||
let request = try request.preparedRequest(db, forSingleResult: false)
|
||||
let request = try request.makePreparedRequest(db, forSingleResult: false)
|
||||
return try fetchCursor(request.statement, adapter: request.adapter)
|
||||
}
|
||||
|
||||
@@ -527,7 +527,7 @@ extension Optional where Wrapped: DatabaseValueConvertible & StatementColumnConv
|
||||
/// - returns: An array of optional values.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public static func fetchAll<R: FetchRequest>(_ db: Database, _ request: R) throws -> [Wrapped?] {
|
||||
let request = try request.preparedRequest(db, forSingleResult: false)
|
||||
let request = try request.makePreparedRequest(db, forSingleResult: false)
|
||||
return try fetchAll(request.statement, adapter: request.adapter)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ extension QueryInterfaceRequest: FetchRequest {
|
||||
/// - parameter singleResult: A hint as to whether the query should be optimized for a single result.
|
||||
/// - returns: A prepared statement and an eventual row adapter.
|
||||
/// :nodoc:
|
||||
public func preparedRequest(_ db: Database, forSingleResult singleResult: Bool) throws -> PreparedRequest {
|
||||
public func makePreparedRequest(_ db: Database, forSingleResult singleResult: Bool) throws -> PreparedRequest {
|
||||
var query = self.query
|
||||
|
||||
// Optimize query by setting a limit of 1 when appropriate
|
||||
|
||||
@@ -276,7 +276,7 @@ extension FetchableRecord {
|
||||
/// - returns: A cursor over fetched records.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public static func fetchCursor<R: FetchRequest>(_ db: Database, _ request: R) throws -> RecordCursor<Self> {
|
||||
let request = try request.preparedRequest(db, forSingleResult: false)
|
||||
let request = try request.makePreparedRequest(db, forSingleResult: false)
|
||||
precondition(request.supplementaryFetch == nil, "Not implemented: fetchCursor with supplementary fetch")
|
||||
return try fetchCursor(request.statement, adapter: request.adapter)
|
||||
}
|
||||
@@ -292,7 +292,7 @@ extension FetchableRecord {
|
||||
/// - returns: An array of records.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public static func fetchAll<R: FetchRequest>(_ db: Database, _ request: R) throws -> [Self] {
|
||||
let request = try request.preparedRequest(db, forSingleResult: false)
|
||||
let request = try request.makePreparedRequest(db, forSingleResult: false)
|
||||
if let supplementaryFetch = request.supplementaryFetch {
|
||||
let rows = try Row.fetchAll(request.statement, adapter: request.adapter)
|
||||
try supplementaryFetch(rows)
|
||||
@@ -313,7 +313,7 @@ extension FetchableRecord {
|
||||
/// - returns: An optional record.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public static func fetchOne<R: FetchRequest>(_ db: Database, _ request: R) throws -> Self? {
|
||||
let request = try request.preparedRequest(db, forSingleResult: true)
|
||||
let request = try request.makePreparedRequest(db, forSingleResult: true)
|
||||
if let supplementaryFetch = request.supplementaryFetch {
|
||||
guard let row = try Row.fetchOne(request.statement, adapter: request.adapter) else {
|
||||
return nil
|
||||
|
||||
@@ -4736,7 +4736,7 @@ protocol FetchRequest: DatabaseRegionConvertible {
|
||||
|
||||
/// Returns a PreparedRequest made of a prepared statement that is ready to
|
||||
/// be executed, and an eventual row adapter.
|
||||
func preparedRequest(_ db: Database, forSingleResult singleResult: Bool) throws -> PreparedRequest
|
||||
func makePreparedRequest(_ db: Database, forSingleResult singleResult: Bool) throws -> PreparedRequest
|
||||
|
||||
/// The number of rows fetched by the request.
|
||||
func fetchCount(_ db: Database) throws -> Int
|
||||
@@ -4745,7 +4745,7 @@ protocol FetchRequest: DatabaseRegionConvertible {
|
||||
|
||||
When the `RowDecoder` associated type is [Row](#fetching-rows), or a [value](#value-queries), or a type that conforms to [FetchableRecord], the request can fetch: see [Fetching From Custom Requests](#fetching-from-custom-requests) below.
|
||||
|
||||
The `preparedRequest(_:forSingleResult:)` method accepts a database connection, a `singleResult` hint, and returns a "prepared request" made of a [prepared statement](#prepared-statements) and an optional [row adapter](#row-adapters). Conforming types can use the `singleResult` hint as an optimization opportunity, and return a statement that fetches at most one row, with a `LIMIT` SQL clause, when possible.
|
||||
The `makePreparedRequest(_:forSingleResult:)` method accepts a database connection, a `singleResult` hint, and returns a "prepared request" made of a [prepared statement](#prepared-statements) and an optional [row adapter](#row-adapters). Conforming types can use the `singleResult` hint as an optimization opportunity, and return a statement that fetches at most one row, with a `LIMIT` SQL clause, when possible.
|
||||
|
||||
The `fetchCount` method has a default implementation that builds a correct but naive SQL query from the statement returned by `prepare`: `SELECT COUNT(*) FROM (...)`. Adopting types can refine the counting SQL by customizing their `fetchCount` implementation.
|
||||
|
||||
|
||||
@@ -112,7 +112,7 @@ private struct UserRowRequest : FetchRequest {
|
||||
typealias RowDecoder = CustomType
|
||||
// TODO: remove when we remove the deprecated prepare(_:forSingleResult:) method
|
||||
func prepare(_ db: Database, forSingleResult singleResult: Bool) throws -> (SelectStatement, RowAdapter?) { preconditionFailure() }
|
||||
func preparedRequest(_ db: Database, forSingleResult singleResult: Bool) throws -> PreparedRequest { preconditionFailure() }
|
||||
func makePreparedRequest(_ db: Database, forSingleResult singleResult: Bool) throws -> PreparedRequest { preconditionFailure() }
|
||||
}
|
||||
|
||||
// MARK: - FetchableRecord
|
||||
|
||||
@@ -37,7 +37,7 @@ class FetchRequestTests: GRDBTestCase {
|
||||
func testRequestFetchRows() throws {
|
||||
struct CustomRequest : FetchRequest {
|
||||
typealias RowDecoder = Row
|
||||
func preparedRequest(_ db: Database, forSingleResult singleResult: Bool) throws -> PreparedRequest {
|
||||
func makePreparedRequest(_ db: Database, forSingleResult singleResult: Bool) throws -> PreparedRequest {
|
||||
return try PreparedRequest(statement: db.makeSelectStatement(sql: "SELECT * FROM table1"))
|
||||
}
|
||||
}
|
||||
@@ -62,7 +62,7 @@ class FetchRequestTests: GRDBTestCase {
|
||||
func testRequestFetchValues() throws {
|
||||
struct CustomRequest : FetchRequest {
|
||||
typealias RowDecoder = Int
|
||||
func preparedRequest(_ db: Database, forSingleResult singleResult: Bool) throws -> PreparedRequest {
|
||||
func makePreparedRequest(_ db: Database, forSingleResult singleResult: Bool) throws -> PreparedRequest {
|
||||
return try PreparedRequest(statement: db.makeSelectStatement(sql: "SELECT id FROM table1"))
|
||||
}
|
||||
}
|
||||
@@ -90,7 +90,7 @@ class FetchRequestTests: GRDBTestCase {
|
||||
}
|
||||
struct CustomRequest : FetchRequest {
|
||||
typealias RowDecoder = CustomRecord
|
||||
func preparedRequest(_ db: Database, forSingleResult singleResult: Bool) throws -> PreparedRequest {
|
||||
func makePreparedRequest(_ db: Database, forSingleResult singleResult: Bool) throws -> PreparedRequest {
|
||||
return try PreparedRequest(statement: db.makeSelectStatement(sql: "SELECT id FROM table1"))
|
||||
}
|
||||
}
|
||||
@@ -115,7 +115,7 @@ class FetchRequestTests: GRDBTestCase {
|
||||
func testRequestFetchCount() throws {
|
||||
struct CustomRequest : FetchRequest {
|
||||
typealias RowDecoder = Row
|
||||
func preparedRequest(_ db: Database, forSingleResult singleResult: Bool) throws -> PreparedRequest {
|
||||
func makePreparedRequest(_ db: Database, forSingleResult singleResult: Bool) throws -> PreparedRequest {
|
||||
return try PreparedRequest(statement: db.makeSelectStatement(sql: "SELECT * FROM table1"))
|
||||
}
|
||||
}
|
||||
@@ -138,7 +138,7 @@ class FetchRequestTests: GRDBTestCase {
|
||||
func testRequestCustomizedFetchCount() throws {
|
||||
struct CustomRequest : FetchRequest {
|
||||
typealias RowDecoder = Row
|
||||
func preparedRequest(_ db: Database, forSingleResult singleResult: Bool) throws -> PreparedRequest {
|
||||
func makePreparedRequest(_ db: Database, forSingleResult singleResult: Bool) throws -> PreparedRequest {
|
||||
return try PreparedRequest(statement: db.makeSelectStatement(sql: "INVALID"))
|
||||
}
|
||||
|
||||
@@ -167,7 +167,7 @@ class FetchRequestTests: GRDBTestCase {
|
||||
func testSingleResultHint() throws {
|
||||
struct CustomRequest<T>: FetchRequest {
|
||||
typealias RowDecoder = T
|
||||
func preparedRequest(_ db: Database, forSingleResult singleResult: Bool) throws -> PreparedRequest {
|
||||
func makePreparedRequest(_ db: Database, forSingleResult singleResult: Bool) throws -> PreparedRequest {
|
||||
if singleResult {
|
||||
return try PreparedRequest(statement: db.makeSelectStatement(sql: "SELECT 'single' AS hint"))
|
||||
} else {
|
||||
@@ -369,7 +369,7 @@ class FetchRequestTests: GRDBTestCase {
|
||||
func testSingleResultHintIsNotUsedForDefaultFetchCount() throws {
|
||||
struct CustomRequest: FetchRequest {
|
||||
typealias RowDecoder = Void
|
||||
func preparedRequest(_ db: Database, forSingleResult singleResult: Bool) throws -> PreparedRequest {
|
||||
func makePreparedRequest(_ db: Database, forSingleResult singleResult: Bool) throws -> PreparedRequest {
|
||||
if singleResult { fatalError("not implemented") }
|
||||
return try PreparedRequest(statement: db.makeSelectStatement(sql: "SELECT 'multiple'"))
|
||||
}
|
||||
@@ -386,7 +386,7 @@ class FetchRequestTests: GRDBTestCase {
|
||||
func testSingleResultHintIsNotUsedForDefaultDatabaseRegion() throws {
|
||||
struct CustomRequest: FetchRequest {
|
||||
typealias RowDecoder = Void
|
||||
func preparedRequest(_ db: Database, forSingleResult singleResult: Bool) throws -> PreparedRequest {
|
||||
func makePreparedRequest(_ db: Database, forSingleResult singleResult: Bool) throws -> PreparedRequest {
|
||||
if singleResult { fatalError("not implemented") }
|
||||
return try PreparedRequest(statement: db.makeSelectStatement(sql: "SELECT * FROM multiple"))
|
||||
}
|
||||
|
||||
@@ -146,7 +146,7 @@ class GRDBTestCase: XCTestCase {
|
||||
|
||||
// Compare SQL strings (ignoring leading and trailing white space and semicolons.
|
||||
func assertEqualSQL<Request: FetchRequest>(_ db: Database, _ request: Request, _ sql: String, file: StaticString = #file, line: UInt = #line) throws {
|
||||
let request = try request.preparedRequest(db, forSingleResult: false)
|
||||
let request = try request.makePreparedRequest(db, forSingleResult: false)
|
||||
try request.statement.makeCursor().next()
|
||||
assertEqualSQL(lastSQLQuery, sql, file: file, line: line)
|
||||
}
|
||||
@@ -160,7 +160,7 @@ class GRDBTestCase: XCTestCase {
|
||||
|
||||
func sql<Request: FetchRequest>(_ databaseReader: DatabaseReader, _ request: Request) -> String {
|
||||
return try! databaseReader.unsafeRead { db in
|
||||
let request = try request.preparedRequest(db, forSingleResult: false)
|
||||
let request = try request.makePreparedRequest(db, forSingleResult: false)
|
||||
try request.statement.makeCursor().next()
|
||||
return lastSQLQuery
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ class SQLRequestTests: GRDBTestCase {
|
||||
func testRequestInitializer() throws {
|
||||
struct CustomRequest: FetchRequest {
|
||||
typealias RowDecoder = Row
|
||||
func preparedRequest(_ db: Database, forSingleResult singleResult: Bool) throws -> PreparedRequest {
|
||||
func makePreparedRequest(_ db: Database, forSingleResult singleResult: Bool) throws -> PreparedRequest {
|
||||
let statement = try db.makeSelectStatement(sql: "SELECT ? AS a, ? AS b")
|
||||
statement.arguments = [1, "foo"]
|
||||
return PreparedRequest(statement: statement)
|
||||
@@ -73,7 +73,7 @@ class SQLRequestTests: GRDBTestCase {
|
||||
func testRequestInitializerAndSingleResultHint() throws {
|
||||
struct CustomRequest: FetchRequest {
|
||||
typealias RowDecoder = Row
|
||||
func preparedRequest(_ db: Database, forSingleResult singleResult: Bool) throws -> PreparedRequest {
|
||||
func makePreparedRequest(_ db: Database, forSingleResult singleResult: Bool) throws -> PreparedRequest {
|
||||
if singleResult { fatalError("not implemented") }
|
||||
return try PreparedRequest(statement: db.makeSelectStatement(sql: "SELECT 'multiple'"))
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user