From f858bcbe5b0400ecb7c5e97151343beeef18ac5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Mon, 22 May 2017 18:55:51 +0200 Subject: [PATCH] Rename Request.fetching(_:) to Request.asRequest(of:) --- CHANGELOG.md | 2 +- GRDB/Core/Request.swift | 5 +- GRDB/Legacy/Fixits-0.109.0.swift | 2 +- GRDB/Record/FetchedRecordsController.swift | 6 +- README.md | 26 +++++-- TODO.md | 2 +- .../DatabaseValueConvertibleFetchTests.swift | 68 +++++++++---------- Tests/GRDBTests/RowAdapterTests.swift | 16 ++--- Tests/GRDBTests/RowConvertibleTests.swift | 40 +++++------ Tests/GRDBTests/RowFetchTests.swift | 40 +++++------ ...StatementColumnConvertibleFetchTests.swift | 64 ++++++++--------- 11 files changed, 144 insertions(+), 127 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a36fa3ec..3bd87d123 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,7 +15,7 @@ Release Notes - `DatabaseEventKind.impacts(_ selectionInfo:SelectStatement.SelectionInfo)` now returns an non-optional boolean. - `DatabaseWriter.availableDatabaseConnection` has been replaced by `DatabaseWriter.unsafeReentrantWrite()`. -- `Request.bound(to:)` has been renamed `Request.fetching(_:)`. +- `Request.bound(to:)` has been renamed `Request.asRequest(of:)`. ## 0.108.0 diff --git a/GRDB/Core/Request.swift b/GRDB/Core/Request.swift index abf326f75..f60b98362 100644 --- a/GRDB/Core/Request.swift +++ b/GRDB/Core/Request.swift @@ -45,14 +45,15 @@ extension Request { /// The returned request can fetch if the type T is fetchable (Row, /// value, record). /// + /// // minHeight in Double? /// let minHeight = Person /// .select(min(heightColumn)) - /// .fetching(Double.self) // <-- + /// .asRequest(of: Double.self) // <-- /// .fetchOne(db) /// /// - parameter type: The fetched type T /// - returns: A typed request bound to type T. - public func fetching(_ type: T.Type) -> AnyTypedRequest { + public func asRequest(of type: T.Type) -> AnyTypedRequest { return AnyTypedRequest { try self.prepare($0) } } diff --git a/GRDB/Legacy/Fixits-0.109.0.swift b/GRDB/Legacy/Fixits-0.109.0.swift index f5362f549..d26a5d501 100644 --- a/GRDB/Legacy/Fixits-0.109.0.swift +++ b/GRDB/Legacy/Fixits-0.109.0.swift @@ -1,4 +1,4 @@ extension Request { - @available(*, unavailable, renamed:"fetching(_:)") + @available(*, unavailable, renamed:"asRequest(of:)") public func bound(to type: T.Type) -> AnyTypedRequest { preconditionFailure() } } diff --git a/GRDB/Record/FetchedRecordsController.swift b/GRDB/Record/FetchedRecordsController.swift index 48be1d07b..dcfea8604 100644 --- a/GRDB/Record/FetchedRecordsController.swift +++ b/GRDB/Record/FetchedRecordsController.swift @@ -38,7 +38,7 @@ public final class FetchedRecordsController { /// This function should return true if the two records have the /// same identity. For example, they have the same id. public convenience init(_ databaseWriter: DatabaseWriter, sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil, queue: DispatchQueue = .main, isSameRecord: ((Record, Record) -> Bool)? = nil) throws { - try self.init(databaseWriter, request: SQLRequest(sql, arguments: arguments, adapter: adapter).fetching(Record.self), queue: queue, isSameRecord: isSameRecord) + try self.init(databaseWriter, request: SQLRequest(sql, arguments: arguments, adapter: adapter).asRequest(of: Record.self), queue: queue, isSameRecord: isSameRecord) } /// Creates a fetched records controller initialized from a fetch request @@ -157,7 +157,7 @@ public final class FetchedRecordsController { /// This method must be used from the controller's dispatch queue (the /// main queue unless stated otherwise in the controller's initializer). public func setRequest(sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws { - try setRequest(SQLRequest(sql, arguments: arguments, adapter: adapter).fetching(Record.self)) + try setRequest(SQLRequest(sql, arguments: arguments, adapter: adapter).asRequest(of: Record.self)) } /// Registers changes notification callbacks. @@ -374,7 +374,7 @@ extension FetchedRecordsController where Record: TableMapping { /// notified of changes in this queue. The controller itself must be /// used from this queue. public convenience init(_ databaseWriter: DatabaseWriter, sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil, queue: DispatchQueue = .main) throws { - try self.init(databaseWriter, request: SQLRequest(sql, arguments: arguments, adapter: adapter).fetching(Record.self), queue: queue) + try self.init(databaseWriter, request: SQLRequest(sql, arguments: arguments, adapter: adapter).asRequest(of: Record.self), queue: queue) } /// Creates a fetched records controller initialized from a fetch request diff --git a/README.md b/README.md index d0491cad1..8370484ea 100644 --- a/README.md +++ b/README.md @@ -3145,10 +3145,26 @@ let maxScore = try Int.fetchOne(db, request) // Int? let request = Player.select(min(scoreColumn), max(scoreColumn)) let row = try Row.fetchOne(db, request)! -let minScore = row.value(atIndex: 0) as Int -let maxScore = row.value(atIndex: 1) as Int +let minScore = row.value(atIndex: 0) as Int? +let maxScore = row.value(atIndex: 1) as Int? ``` +The examples above can also be rewritten using the `asRequest(of:)` method: + +```swift +let maxScore = try Player.select(max(scoreColumn)) + .asRequest(of: Int.self) + .fetchOne(db) + +let row = try Player.select(min(scoreColumn), max(scoreColumn)) + .asRequest(of: Row.self) + .fetchOne(db)! +let minScore = row.value(atIndex: 0) as Int? +let maxScore = row.value(atIndex: 1) as Int? +``` + +More information about `asRequest(of:)` can be found in the [Custom Requests](#custom-requests) chapter. + ## Delete Requests @@ -3287,7 +3303,7 @@ Rebind the fetched type of requests: ```swift let maxScore = Player.select(max(scoreColumn)) - .fetching(Int.self) + .asRequest(of: Int.self) .fetchOne(db) ``` @@ -3297,7 +3313,7 @@ Bind custom SQL requests to your record types: extension Person { static func customRequest(...) -> AnyTypedRequest { let request = SQLRequest("SELECT ...", arguments: ...) - return request.fetching(Person.self) + return request.asRequest(of: Person.self) } } @@ -3322,7 +3338,7 @@ struct BookAuthorPair : RowConvertible { "SELECT books.*, authors.* " + "FROM books " + "JOIN authors ON authors.id = books.authorID") - .fetching(BookAuthorPair.self) + .asRequest(of: BookAuthorPair.self) .adapted { db in // The scopes are used in init(row:) try ScopeAdapter([ diff --git a/TODO.md b/TODO.md index 4e8758e17..279c7a864 100644 --- a/TODO.md +++ b/TODO.md @@ -25,7 +25,7 @@ v1.0 checklit Besides, not all requests have a naturel Fetched type: request.fetchCount(db) doesn't care about the type of the request, for example. - [X] Question AnyRequest and AnyTypedRequest as results (for example, `SQLRequest("...").bound(to: MyRecord.self)` returns AnyTypedRequest). It's not worth the effort to introduce more concrete request types (AdaptedRequest, AdaptedTypedRequest, BoundRequest) - - [X] Question the naming of the `request.bound(to:T.self)` method. Prefer... `request.fetching(T.self)`? `request.of(T.self)`? + - [X] Question the naming of the `request.bound(to:T.self)` method. Prefer... `request..asRequest(of: T.self)` - [ ] Make GRDB less stringly-typed. When a user defines a static list of columns for a record type, those columns should be easier to use: - [ ] Persistable.persistentDictionary requires string keys, doesn't accept columns - [ ] If possible, improve on `Person.filter(Person.email != nil)` or `Person.filter(Person.Column.email != nil)` (see [#186](https://github.com/groue/GRDB.swift/issues/186)) diff --git a/Tests/GRDBTests/DatabaseValueConvertibleFetchTests.swift b/Tests/GRDBTests/DatabaseValueConvertibleFetchTests.swift index 473702022..85d649b54 100644 --- a/Tests/GRDBTests/DatabaseValueConvertibleFetchTests.swift +++ b/Tests/GRDBTests/DatabaseValueConvertibleFetchTests.swift @@ -42,7 +42,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { try test(Fetched.fetchCursor(db, sql)) try test(Fetched.fetchCursor(statement)) try test(Fetched.fetchCursor(db, SQLRequest(sql))) - try test(SQLRequest(sql).fetching(Fetched.self).fetchCursor(db)) + try test(SQLRequest(sql).asRequest(of: Fetched.self).fetchCursor(db)) } do { let sql = "SELECT 0, 1 UNION ALL SELECT 0, 2" @@ -51,7 +51,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { try test(Fetched.fetchCursor(db, sql, adapter: adapter)) try test(Fetched.fetchCursor(statement, adapter: adapter)) try test(Fetched.fetchCursor(db, SQLRequest(sql, adapter: adapter))) - try test(SQLRequest(sql, adapter: adapter).fetching(Fetched.self).fetchCursor(db)) + try test(SQLRequest(sql, adapter: adapter).asRequest(of: Fetched.self).fetchCursor(db)) } } } @@ -86,7 +86,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { try test(Fetched.fetchCursor(db, sql), sql: sql) try test(Fetched.fetchCursor(db.makeSelectStatement(sql)), sql: sql) try test(Fetched.fetchCursor(db, SQLRequest(sql)), sql: sql) - try test(SQLRequest(sql).fetching(Fetched.self).fetchCursor(db), sql: sql) + try test(SQLRequest(sql).asRequest(of: Fetched.self).fetchCursor(db), sql: sql) } do { let sql = "SELECT 0, throw()" @@ -94,7 +94,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { try test(Fetched.fetchCursor(db, sql, adapter: adapter), sql: sql) try test(Fetched.fetchCursor(db.makeSelectStatement(sql), adapter: adapter), sql: sql) try test(Fetched.fetchCursor(db, SQLRequest(sql, adapter: adapter)), sql: sql) - try test(SQLRequest(sql, adapter: adapter).fetching(Fetched.self).fetchCursor(db), sql: sql) + try test(SQLRequest(sql, adapter: adapter).asRequest(of: Fetched.self).fetchCursor(db), sql: sql) } } } @@ -118,7 +118,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { try test(Fetched.fetchCursor(db, sql), sql: sql) try test(Fetched.fetchCursor(db.makeSelectStatement(sql)), sql: sql) try test(Fetched.fetchCursor(db, SQLRequest(sql)), sql: sql) - try test(SQLRequest(sql).fetching(Fetched.self).fetchCursor(db), sql: sql) + try test(SQLRequest(sql).asRequest(of: Fetched.self).fetchCursor(db), sql: sql) } do { let sql = "SELECT * FROM nonExistingTable" @@ -126,7 +126,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { try test(Fetched.fetchCursor(db, sql, adapter: adapter), sql: sql) try test(Fetched.fetchCursor(db.makeSelectStatement(sql), adapter: adapter), sql: sql) try test(Fetched.fetchCursor(db, SQLRequest(sql, adapter: adapter)), sql: sql) - try test(SQLRequest(sql, adapter: adapter).fetching(Fetched.self).fetchCursor(db), sql: sql) + try test(SQLRequest(sql, adapter: adapter).asRequest(of: Fetched.self).fetchCursor(db), sql: sql) } } } @@ -143,7 +143,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { try test(Fetched.fetchAll(db, sql)) try test(Fetched.fetchAll(statement)) try test(Fetched.fetchAll(db, SQLRequest(sql))) - try test(SQLRequest(sql).fetching(Fetched.self).fetchAll(db)) + try test(SQLRequest(sql).asRequest(of: Fetched.self).fetchAll(db)) } do { let sql = "SELECT 0, 1 UNION ALL SELECT 0, 2" @@ -152,7 +152,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { try test(Fetched.fetchAll(db, sql, adapter: adapter)) try test(Fetched.fetchAll(statement, adapter: adapter)) try test(Fetched.fetchAll(db, SQLRequest(sql, adapter: adapter))) - try test(SQLRequest(sql, adapter: adapter).fetching(Fetched.self).fetchAll(db)) + try test(SQLRequest(sql, adapter: adapter).asRequest(of: Fetched.self).fetchAll(db)) } } } @@ -178,7 +178,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { try test(Fetched.fetchAll(db, sql), sql: sql) try test(Fetched.fetchAll(db.makeSelectStatement(sql)), sql: sql) try test(Fetched.fetchAll(db, SQLRequest(sql)), sql: sql) - try test(SQLRequest(sql).fetching(Fetched.self).fetchAll(db), sql: sql) + try test(SQLRequest(sql).asRequest(of: Fetched.self).fetchAll(db), sql: sql) } do { let sql = "SELECT 0, throw()" @@ -186,7 +186,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { try test(Fetched.fetchAll(db, sql, adapter: adapter), sql: sql) try test(Fetched.fetchAll(db.makeSelectStatement(sql), adapter: adapter), sql: sql) try test(Fetched.fetchAll(db, SQLRequest(sql, adapter: adapter)), sql: sql) - try test(SQLRequest(sql, adapter: adapter).fetching(Fetched.self).fetchAll(db), sql: sql) + try test(SQLRequest(sql, adapter: adapter).asRequest(of: Fetched.self).fetchAll(db), sql: sql) } } } @@ -210,7 +210,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { try test(Fetched.fetchAll(db, sql), sql: sql) try test(Fetched.fetchAll(db.makeSelectStatement(sql)), sql: sql) try test(Fetched.fetchAll(db, SQLRequest(sql)), sql: sql) - try test(SQLRequest(sql).fetching(Fetched.self).fetchAll(db), sql: sql) + try test(SQLRequest(sql).asRequest(of: Fetched.self).fetchAll(db), sql: sql) } do { let sql = "SELECT * FROM nonExistingTable" @@ -218,7 +218,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { try test(Fetched.fetchAll(db, sql, adapter: adapter), sql: sql) try test(Fetched.fetchAll(db.makeSelectStatement(sql), adapter: adapter), sql: sql) try test(Fetched.fetchAll(db, SQLRequest(sql, adapter: adapter)), sql: sql) - try test(SQLRequest(sql, adapter: adapter).fetching(Fetched.self).fetchAll(db), sql: sql) + try test(SQLRequest(sql, adapter: adapter).asRequest(of: Fetched.self).fetchAll(db), sql: sql) } } } @@ -236,7 +236,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { try test(Fetched.fetchOne(db, sql)) try test(Fetched.fetchOne(statement)) try test(Fetched.fetchOne(db, SQLRequest(sql))) - try test(SQLRequest(sql).fetching(Fetched.self).fetchOne(db)) + try test(SQLRequest(sql).asRequest(of: Fetched.self).fetchOne(db)) } do { let sql = "SELECT 0, 1 WHERE 0" @@ -245,7 +245,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { try test(Fetched.fetchOne(db, sql, adapter: adapter)) try test(Fetched.fetchOne(statement, adapter: adapter)) try test(Fetched.fetchOne(db, SQLRequest(sql, adapter: adapter))) - try test(SQLRequest(sql, adapter: adapter).fetching(Fetched.self).fetchOne(db)) + try test(SQLRequest(sql, adapter: adapter).asRequest(of: Fetched.self).fetchOne(db)) } } do { @@ -258,7 +258,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { try test(Fetched.fetchOne(db, sql)) try test(Fetched.fetchOne(statement)) try test(Fetched.fetchOne(db, SQLRequest(sql))) - try test(SQLRequest(sql).fetching(Fetched.self).fetchOne(db)) + try test(SQLRequest(sql).asRequest(of: Fetched.self).fetchOne(db)) } do { let sql = "SELECT 0, NULL" @@ -267,7 +267,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { try test(Fetched.fetchOne(db, sql, adapter: adapter)) try test(Fetched.fetchOne(statement, adapter: adapter)) try test(Fetched.fetchOne(db, SQLRequest(sql, adapter: adapter))) - try test(SQLRequest(sql, adapter: adapter).fetching(Fetched.self).fetchOne(db)) + try test(SQLRequest(sql, adapter: adapter).asRequest(of: Fetched.self).fetchOne(db)) } } do { @@ -280,7 +280,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { try test(Fetched.fetchOne(db, sql)) try test(Fetched.fetchOne(statement)) try test(Fetched.fetchOne(db, SQLRequest(sql))) - try test(SQLRequest(sql).fetching(Fetched.self).fetchOne(db)) + try test(SQLRequest(sql).asRequest(of: Fetched.self).fetchOne(db)) } do { let sql = "SELECT 0, 1" @@ -289,7 +289,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { try test(Fetched.fetchOne(db, sql, adapter: adapter)) try test(Fetched.fetchOne(statement, adapter: adapter)) try test(Fetched.fetchOne(db, SQLRequest(sql, adapter: adapter))) - try test(SQLRequest(sql, adapter: adapter).fetching(Fetched.self).fetchOne(db)) + try test(SQLRequest(sql, adapter: adapter).asRequest(of: Fetched.self).fetchOne(db)) } } } @@ -316,7 +316,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { try test(Fetched.fetchOne(db, sql), sql: sql) try test(Fetched.fetchOne(db.makeSelectStatement(sql)), sql: sql) try test(Fetched.fetchOne(db, SQLRequest(sql)), sql: sql) - try test(SQLRequest(sql).fetching(Fetched.self).fetchOne(db), sql: sql) + try test(SQLRequest(sql).asRequest(of: Fetched.self).fetchOne(db), sql: sql) } do { let sql = "SELECT 0, throw()" @@ -324,7 +324,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { try test(Fetched.fetchOne(db, sql, adapter: adapter), sql: sql) try test(Fetched.fetchOne(db.makeSelectStatement(sql), adapter: adapter), sql: sql) try test(Fetched.fetchOne(db, SQLRequest(sql, adapter: adapter)), sql: sql) - try test(SQLRequest(sql, adapter: adapter).fetching(Fetched.self).fetchOne(db), sql: sql) + try test(SQLRequest(sql, adapter: adapter).asRequest(of: Fetched.self).fetchOne(db), sql: sql) } } } @@ -348,7 +348,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { try test(Fetched.fetchOne(db, sql), sql: sql) try test(Fetched.fetchOne(db.makeSelectStatement(sql)), sql: sql) try test(Fetched.fetchOne(db, SQLRequest(sql)), sql: sql) - try test(SQLRequest(sql).fetching(Fetched.self).fetchOne(db), sql: sql) + try test(SQLRequest(sql).asRequest(of: Fetched.self).fetchOne(db), sql: sql) } do { let sql = "SELECT * FROM nonExistingTable" @@ -356,7 +356,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { try test(Fetched.fetchOne(db, sql, adapter: adapter), sql: sql) try test(Fetched.fetchOne(db.makeSelectStatement(sql), adapter: adapter), sql: sql) try test(Fetched.fetchOne(db, SQLRequest(sql, adapter: adapter)), sql: sql) - try test(SQLRequest(sql, adapter: adapter).fetching(Fetched.self).fetchOne(db), sql: sql) + try test(SQLRequest(sql, adapter: adapter).asRequest(of: Fetched.self).fetchOne(db), sql: sql) } } } @@ -377,7 +377,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { try test(Optional.fetchCursor(db, sql)) try test(Optional.fetchCursor(statement)) try test(Optional.fetchCursor(db, SQLRequest(sql))) - try test(SQLRequest(sql).fetching(Optional.self).fetchCursor(db)) + try test(SQLRequest(sql).asRequest(of: Optional.self).fetchCursor(db)) } do { let sql = "SELECT 0, 1 UNION ALL SELECT 0, NULL" @@ -386,7 +386,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { try test(Optional.fetchCursor(db, sql, adapter: adapter)) try test(Optional.fetchCursor(statement, adapter: adapter)) try test(Optional.fetchCursor(db, SQLRequest(sql, adapter: adapter))) - try test(SQLRequest(sql, adapter: adapter).fetching(Optional.self).fetchCursor(db)) + try test(SQLRequest(sql, adapter: adapter).asRequest(of: Optional.self).fetchCursor(db)) } } } @@ -421,7 +421,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { try test(Optional.fetchCursor(db, sql), sql: sql) try test(Optional.fetchCursor(db.makeSelectStatement(sql)), sql: sql) try test(Optional.fetchCursor(db, SQLRequest(sql)), sql: sql) - try test(SQLRequest(sql).fetching(Optional.self).fetchCursor(db), sql: sql) + try test(SQLRequest(sql).asRequest(of: Optional.self).fetchCursor(db), sql: sql) } do { let sql = "SELECT 0, throw()" @@ -429,7 +429,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { try test(Optional.fetchCursor(db, sql, adapter: adapter), sql: sql) try test(Optional.fetchCursor(db.makeSelectStatement(sql), adapter: adapter), sql: sql) try test(Optional.fetchCursor(db, SQLRequest(sql, adapter: adapter)), sql: sql) - try test(SQLRequest(sql, adapter: adapter).fetching(Optional.self).fetchCursor(db), sql: sql) + try test(SQLRequest(sql, adapter: adapter).asRequest(of: Optional.self).fetchCursor(db), sql: sql) } } } @@ -453,7 +453,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { try test(Optional.fetchCursor(db, sql), sql: sql) try test(Optional.fetchCursor(db.makeSelectStatement(sql)), sql: sql) try test(Optional.fetchCursor(db, SQLRequest(sql)), sql: sql) - try test(SQLRequest(sql).fetching(Optional.self).fetchCursor(db), sql: sql) + try test(SQLRequest(sql).asRequest(of: Optional.self).fetchCursor(db), sql: sql) } do { let sql = "SELECT * FROM nonExistingTable" @@ -461,7 +461,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { try test(Optional.fetchCursor(db, sql, adapter: adapter), sql: sql) try test(Optional.fetchCursor(db.makeSelectStatement(sql), adapter: adapter), sql: sql) try test(Optional.fetchCursor(db, SQLRequest(sql, adapter: adapter)), sql: sql) - try test(SQLRequest(sql, adapter: adapter).fetching(Optional.self).fetchCursor(db), sql: sql) + try test(SQLRequest(sql, adapter: adapter).asRequest(of: Optional.self).fetchCursor(db), sql: sql) } } } @@ -480,7 +480,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { try test(Optional.fetchAll(db, sql)) try test(Optional.fetchAll(statement)) try test(Optional.fetchAll(db, SQLRequest(sql))) - try test(SQLRequest(sql).fetching(Optional.self).fetchAll(db)) + try test(SQLRequest(sql).asRequest(of: Optional.self).fetchAll(db)) } do { let sql = "SELECT 0, 1 UNION ALL SELECT 0, NULL" @@ -489,7 +489,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { try test(Optional.fetchAll(db, sql, adapter: adapter)) try test(Optional.fetchAll(statement, adapter: adapter)) try test(Optional.fetchAll(db, SQLRequest(sql, adapter: adapter))) - try test(SQLRequest(sql, adapter: adapter).fetching(Optional.self).fetchAll(db)) + try test(SQLRequest(sql, adapter: adapter).asRequest(of: Optional.self).fetchAll(db)) } } } @@ -515,7 +515,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { try test(Optional.fetchAll(db, sql), sql: sql) try test(Optional.fetchAll(db.makeSelectStatement(sql)), sql: sql) try test(Optional.fetchAll(db, SQLRequest(sql)), sql: sql) - try test(SQLRequest(sql).fetching(Optional.self).fetchAll(db), sql: sql) + try test(SQLRequest(sql).asRequest(of: Optional.self).fetchAll(db), sql: sql) } do { let sql = "SELECT 0, throw()" @@ -523,7 +523,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { try test(Optional.fetchAll(db, sql, adapter: adapter), sql: sql) try test(Optional.fetchAll(db.makeSelectStatement(sql), adapter: adapter), sql: sql) try test(Optional.fetchAll(db, SQLRequest(sql, adapter: adapter)), sql: sql) - try test(SQLRequest(sql, adapter: adapter).fetching(Optional.self).fetchAll(db), sql: sql) + try test(SQLRequest(sql, adapter: adapter).asRequest(of: Optional.self).fetchAll(db), sql: sql) } } } @@ -547,7 +547,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { try test(Optional.fetchAll(db, sql), sql: sql) try test(Optional.fetchAll(db.makeSelectStatement(sql)), sql: sql) try test(Optional.fetchAll(db, SQLRequest(sql)), sql: sql) - try test(SQLRequest(sql).fetching(Optional.self).fetchAll(db), sql: sql) + try test(SQLRequest(sql).asRequest(of: Optional.self).fetchAll(db), sql: sql) } do { let sql = "SELECT * FROM nonExistingTable" @@ -555,7 +555,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { try test(Optional.fetchAll(db, sql, adapter: adapter), sql: sql) try test(Optional.fetchAll(db.makeSelectStatement(sql), adapter: adapter), sql: sql) try test(Optional.fetchAll(db, SQLRequest(sql, adapter: adapter)), sql: sql) - try test(SQLRequest(sql, adapter: adapter).fetching(Optional.self).fetchAll(db), sql: sql) + try test(SQLRequest(sql, adapter: adapter).asRequest(of: Optional.self).fetchAll(db), sql: sql) } } } diff --git a/Tests/GRDBTests/RowAdapterTests.swift b/Tests/GRDBTests/RowAdapterTests.swift index f6b6d33bb..382debd1d 100644 --- a/Tests/GRDBTests/RowAdapterTests.swift +++ b/Tests/GRDBTests/RowAdapterTests.swift @@ -668,7 +668,7 @@ class AdapterRowTests : RowTestCase { try dbQueue.inDatabase { db in do { let row = try SQLRequest("SELECT 0 AS a0, 1 AS a1, 2 AS a2", adapter: SuffixRowAdapter(fromIndex: 1)) - .fetching(Row.self) + .asRequest(of: Row.self) .fetchOne(db)! XCTAssertEqual(Array(row.columnNames), ["a1", "a2"]) XCTAssertEqual(Array(row.databaseValues), [1.databaseValue, 2.databaseValue]) @@ -676,7 +676,7 @@ class AdapterRowTests : RowTestCase { do { let row = try SQLRequest("SELECT 0 AS a0, 1 AS a1, 2 AS a2") .adapted { _ in SuffixRowAdapter(fromIndex: 1) } - .fetching(Row.self) + .asRequest(of: Row.self) .fetchOne(db)! XCTAssertEqual(Array(row.columnNames), ["a1", "a2"]) XCTAssertEqual(Array(row.databaseValues), [1.databaseValue, 2.databaseValue]) @@ -684,7 +684,7 @@ class AdapterRowTests : RowTestCase { do { let row = try SQLRequest("SELECT 0 AS a0, 1 AS a1, 2 AS a2", adapter: SuffixRowAdapter(fromIndex: 1)) .adapted { _ in SuffixRowAdapter(fromIndex: 1) } - .fetching(Row.self) + .asRequest(of: Row.self) .fetchOne(db)! XCTAssertEqual(Array(row.columnNames), ["a2"]) XCTAssertEqual(Array(row.databaseValues), [2.databaseValue]) @@ -692,7 +692,7 @@ class AdapterRowTests : RowTestCase { do { let row = try SQLRequest("SELECT 0 AS a0", adapter: ColumnMapping(["a1": "a0"])) .adapted { _ in ColumnMapping(["a2": "a1"]) } - .fetching(Row.self) + .asRequest(of: Row.self) .fetchOne(db)! XCTAssertEqual(Array(row.columnNames), ["a2"]) XCTAssertEqual(Array(row.databaseValues), [0.databaseValue]) @@ -705,14 +705,14 @@ class AdapterRowTests : RowTestCase { try dbQueue.inDatabase { db in do { let row = try SQLRequest("SELECT 0 AS a0, 1 AS a1, 2 AS a2", adapter: SuffixRowAdapter(fromIndex: 1)) - .fetching(Row.self) + .asRequest(of: Row.self) .fetchOne(db)! XCTAssertEqual(Array(row.columnNames), ["a1", "a2"]) XCTAssertEqual(Array(row.databaseValues), [1.databaseValue, 2.databaseValue]) } do { let row = try SQLRequest("SELECT 0 AS a0, 1 AS a1, 2 AS a2") - .fetching(Row.self) + .asRequest(of: Row.self) .adapted { _ in SuffixRowAdapter(fromIndex: 1) } .fetchOne(db)! XCTAssertEqual(Array(row.columnNames), ["a1", "a2"]) @@ -720,7 +720,7 @@ class AdapterRowTests : RowTestCase { } do { let row = try SQLRequest("SELECT 0 AS a0, 1 AS a1, 2 AS a2", adapter: SuffixRowAdapter(fromIndex: 1)) - .fetching(Row.self) + .asRequest(of: Row.self) .adapted { _ in SuffixRowAdapter(fromIndex: 1) } .fetchOne(db)! XCTAssertEqual(Array(row.columnNames), ["a2"]) @@ -728,7 +728,7 @@ class AdapterRowTests : RowTestCase { } do { let row = try SQLRequest("SELECT 0 AS a0", adapter: ColumnMapping(["a1": "a0"])) - .fetching(Row.self) + .asRequest(of: Row.self) .adapted { _ in ColumnMapping(["a2": "a1"]) } .fetchOne(db)! XCTAssertEqual(Array(row.columnNames), ["a2"]) diff --git a/Tests/GRDBTests/RowConvertibleTests.swift b/Tests/GRDBTests/RowConvertibleTests.swift index 6e9c62d09..9bbb12863 100644 --- a/Tests/GRDBTests/RowConvertibleTests.swift +++ b/Tests/GRDBTests/RowConvertibleTests.swift @@ -46,7 +46,7 @@ class RowConvertibleTests: GRDBTestCase { try test(Fetched.fetchCursor(db, sql)) try test(Fetched.fetchCursor(statement)) try test(Fetched.fetchCursor(db, SQLRequest(sql))) - try test(SQLRequest(sql).fetching(Fetched.self).fetchCursor(db)) + try test(SQLRequest(sql).asRequest(of: Fetched.self).fetchCursor(db)) } do { let sql = "SELECT 0 AS firstName, 'Arthur' AS firstName, 'Martin' AS lastName UNION ALL SELECT 0, 'Barbara', 'Gourde'" @@ -55,7 +55,7 @@ class RowConvertibleTests: GRDBTestCase { try test(Fetched.fetchCursor(db, sql, adapter: adapter)) try test(Fetched.fetchCursor(statement, adapter: adapter)) try test(Fetched.fetchCursor(db, SQLRequest(sql, adapter: adapter))) - try test(SQLRequest(sql, adapter: adapter).fetching(Fetched.self).fetchCursor(db)) + try test(SQLRequest(sql, adapter: adapter).asRequest(of: Fetched.self).fetchCursor(db)) } } } @@ -90,7 +90,7 @@ class RowConvertibleTests: GRDBTestCase { try test(Fetched.fetchCursor(db, sql), sql: sql) try test(Fetched.fetchCursor(db.makeSelectStatement(sql)), sql: sql) try test(Fetched.fetchCursor(db, SQLRequest(sql)), sql: sql) - try test(SQLRequest(sql).fetching(Fetched.self).fetchCursor(db), sql: sql) + try test(SQLRequest(sql).asRequest(of: Fetched.self).fetchCursor(db), sql: sql) } do { let sql = "SELECT 0, throw(), NULL" @@ -98,7 +98,7 @@ class RowConvertibleTests: GRDBTestCase { try test(Fetched.fetchCursor(db, sql, adapter: adapter), sql: sql) try test(Fetched.fetchCursor(db.makeSelectStatement(sql), adapter: adapter), sql: sql) try test(Fetched.fetchCursor(db, SQLRequest(sql, adapter: adapter)), sql: sql) - try test(SQLRequest(sql, adapter: adapter).fetching(Fetched.self).fetchCursor(db), sql: sql) + try test(SQLRequest(sql, adapter: adapter).asRequest(of: Fetched.self).fetchCursor(db), sql: sql) } } } @@ -122,7 +122,7 @@ class RowConvertibleTests: GRDBTestCase { try test(Fetched.fetchCursor(db, sql), sql: sql) try test(Fetched.fetchCursor(db.makeSelectStatement(sql)), sql: sql) try test(Fetched.fetchCursor(db, SQLRequest(sql)), sql: sql) - try test(SQLRequest(sql).fetching(Fetched.self).fetchCursor(db), sql: sql) + try test(SQLRequest(sql).asRequest(of: Fetched.self).fetchCursor(db), sql: sql) } do { let sql = "SELECT * FROM nonExistingTable" @@ -130,7 +130,7 @@ class RowConvertibleTests: GRDBTestCase { try test(Fetched.fetchCursor(db, sql, adapter: adapter), sql: sql) try test(Fetched.fetchCursor(db.makeSelectStatement(sql), adapter: adapter), sql: sql) try test(Fetched.fetchCursor(db, SQLRequest(sql, adapter: adapter)), sql: sql) - try test(SQLRequest(sql, adapter: adapter).fetching(Fetched.self).fetchCursor(db), sql: sql) + try test(SQLRequest(sql, adapter: adapter).asRequest(of: Fetched.self).fetchCursor(db), sql: sql) } } } @@ -148,7 +148,7 @@ class RowConvertibleTests: GRDBTestCase { try test(Fetched.fetchAll(db, sql)) try test(Fetched.fetchAll(statement)) try test(Fetched.fetchAll(db, SQLRequest(sql))) - try test(SQLRequest(sql).fetching(Fetched.self).fetchAll(db)) + try test(SQLRequest(sql).asRequest(of: Fetched.self).fetchAll(db)) } do { let sql = "SELECT 0 AS firstName, 'Arthur' AS firstName, 'Martin' AS lastName UNION ALL SELECT 0, 'Barbara', 'Gourde'" @@ -157,7 +157,7 @@ class RowConvertibleTests: GRDBTestCase { try test(Fetched.fetchAll(db, sql, adapter: adapter)) try test(Fetched.fetchAll(statement, adapter: adapter)) try test(Fetched.fetchAll(db, SQLRequest(sql, adapter: adapter))) - try test(SQLRequest(sql, adapter: adapter).fetching(Fetched.self).fetchAll(db)) + try test(SQLRequest(sql, adapter: adapter).asRequest(of: Fetched.self).fetchAll(db)) } } } @@ -183,7 +183,7 @@ class RowConvertibleTests: GRDBTestCase { try test(Fetched.fetchAll(db, sql), sql: sql) try test(Fetched.fetchAll(db.makeSelectStatement(sql)), sql: sql) try test(Fetched.fetchAll(db, SQLRequest(sql)), sql: sql) - try test(SQLRequest(sql).fetching(Fetched.self).fetchAll(db), sql: sql) + try test(SQLRequest(sql).asRequest(of: Fetched.self).fetchAll(db), sql: sql) } do { let sql = "SELECT 0, throw()" @@ -191,7 +191,7 @@ class RowConvertibleTests: GRDBTestCase { try test(Fetched.fetchAll(db, sql, adapter: adapter), sql: sql) try test(Fetched.fetchAll(db.makeSelectStatement(sql), adapter: adapter), sql: sql) try test(Fetched.fetchAll(db, SQLRequest(sql, adapter: adapter)), sql: sql) - try test(SQLRequest(sql, adapter: adapter).fetching(Fetched.self).fetchAll(db), sql: sql) + try test(SQLRequest(sql, adapter: adapter).asRequest(of: Fetched.self).fetchAll(db), sql: sql) } } } @@ -215,7 +215,7 @@ class RowConvertibleTests: GRDBTestCase { try test(Fetched.fetchAll(db, sql), sql: sql) try test(Fetched.fetchAll(db.makeSelectStatement(sql)), sql: sql) try test(Fetched.fetchAll(db, SQLRequest(sql)), sql: sql) - try test(SQLRequest(sql).fetching(Fetched.self).fetchAll(db), sql: sql) + try test(SQLRequest(sql).asRequest(of: Fetched.self).fetchAll(db), sql: sql) } do { let sql = "SELECT * FROM nonExistingTable" @@ -223,7 +223,7 @@ class RowConvertibleTests: GRDBTestCase { try test(Fetched.fetchAll(db, sql, adapter: adapter), sql: sql) try test(Fetched.fetchAll(db.makeSelectStatement(sql), adapter: adapter), sql: sql) try test(Fetched.fetchAll(db, SQLRequest(sql, adapter: adapter)), sql: sql) - try test(SQLRequest(sql, adapter: adapter).fetching(Fetched.self).fetchAll(db), sql: sql) + try test(SQLRequest(sql, adapter: adapter).asRequest(of: Fetched.self).fetchAll(db), sql: sql) } } } @@ -241,7 +241,7 @@ class RowConvertibleTests: GRDBTestCase { try test(Fetched.fetchOne(db, sql)) try test(Fetched.fetchOne(statement)) try test(Fetched.fetchOne(db, SQLRequest(sql))) - try test(SQLRequest(sql).fetching(Fetched.self).fetchOne(db)) + try test(SQLRequest(sql).asRequest(of: Fetched.self).fetchOne(db)) } do { let sql = "SELECT 0, 1 WHERE 0" @@ -250,7 +250,7 @@ class RowConvertibleTests: GRDBTestCase { try test(Fetched.fetchOne(db, sql, adapter: adapter)) try test(Fetched.fetchOne(statement, adapter: adapter)) try test(Fetched.fetchOne(db, SQLRequest(sql, adapter: adapter))) - try test(SQLRequest(sql, adapter: adapter).fetching(Fetched.self).fetchOne(db)) + try test(SQLRequest(sql, adapter: adapter).asRequest(of: Fetched.self).fetchOne(db)) } } do { @@ -264,7 +264,7 @@ class RowConvertibleTests: GRDBTestCase { try test(Fetched.fetchOne(db, sql)) try test(Fetched.fetchOne(statement)) try test(Fetched.fetchOne(db, SQLRequest(sql))) - try test(SQLRequest(sql).fetching(Fetched.self).fetchOne(db)) + try test(SQLRequest(sql).asRequest(of: Fetched.self).fetchOne(db)) } do { let sql = "SELECT 0 AS firstName, 'Arthur' AS firstName, 'Martin' AS lastName" @@ -273,7 +273,7 @@ class RowConvertibleTests: GRDBTestCase { try test(Fetched.fetchOne(db, sql, adapter: adapter)) try test(Fetched.fetchOne(statement, adapter: adapter)) try test(Fetched.fetchOne(db, SQLRequest(sql, adapter: adapter))) - try test(SQLRequest(sql, adapter: adapter).fetching(Fetched.self).fetchOne(db)) + try test(SQLRequest(sql, adapter: adapter).asRequest(of: Fetched.self).fetchOne(db)) } } } @@ -300,7 +300,7 @@ class RowConvertibleTests: GRDBTestCase { try test(Fetched.fetchOne(db, sql), sql: sql) try test(Fetched.fetchOne(db.makeSelectStatement(sql)), sql: sql) try test(Fetched.fetchOne(db, SQLRequest(sql)), sql: sql) - try test(SQLRequest(sql).fetching(Fetched.self).fetchOne(db), sql: sql) + try test(SQLRequest(sql).asRequest(of: Fetched.self).fetchOne(db), sql: sql) } do { let sql = "SELECT 0, throw()" @@ -308,7 +308,7 @@ class RowConvertibleTests: GRDBTestCase { try test(Fetched.fetchOne(db, sql, adapter: adapter), sql: sql) try test(Fetched.fetchOne(db.makeSelectStatement(sql), adapter: adapter), sql: sql) try test(Fetched.fetchOne(db, SQLRequest(sql, adapter: adapter)), sql: sql) - try test(SQLRequest(sql, adapter: adapter).fetching(Fetched.self).fetchOne(db), sql: sql) + try test(SQLRequest(sql, adapter: adapter).asRequest(of: Fetched.self).fetchOne(db), sql: sql) } } } @@ -332,7 +332,7 @@ class RowConvertibleTests: GRDBTestCase { try test(Fetched.fetchOne(db, sql), sql: sql) try test(Fetched.fetchOne(db.makeSelectStatement(sql)), sql: sql) try test(Fetched.fetchOne(db, SQLRequest(sql)), sql: sql) - try test(SQLRequest(sql).fetching(Fetched.self).fetchOne(db), sql: sql) + try test(SQLRequest(sql).asRequest(of: Fetched.self).fetchOne(db), sql: sql) } do { let sql = "SELECT * FROM nonExistingTable" @@ -340,7 +340,7 @@ class RowConvertibleTests: GRDBTestCase { try test(Fetched.fetchOne(db, sql, adapter: adapter), sql: sql) try test(Fetched.fetchOne(db.makeSelectStatement(sql), adapter: adapter), sql: sql) try test(Fetched.fetchOne(db, SQLRequest(sql, adapter: adapter)), sql: sql) - try test(SQLRequest(sql, adapter: adapter).fetching(Fetched.self).fetchOne(db), sql: sql) + try test(SQLRequest(sql, adapter: adapter).asRequest(of: Fetched.self).fetchOne(db), sql: sql) } } } diff --git a/Tests/GRDBTests/RowFetchTests.swift b/Tests/GRDBTests/RowFetchTests.swift index 81126e668..8649ece31 100644 --- a/Tests/GRDBTests/RowFetchTests.swift +++ b/Tests/GRDBTests/RowFetchTests.swift @@ -27,7 +27,7 @@ class RowFetchTests: GRDBTestCase { try test(Row.fetchCursor(db, sql)) try test(Row.fetchCursor(statement)) try test(Row.fetchCursor(db, SQLRequest(sql))) - try test(SQLRequest(sql).fetching(Row.self).fetchCursor(db)) + try test(SQLRequest(sql).asRequest(of: Row.self).fetchCursor(db)) } do { let sql = "SELECT 0 AS firstName, 'Arthur' AS firstName, 'Martin' AS lastName UNION ALL SELECT 0, 'Barbara', 'Gourde'" @@ -36,7 +36,7 @@ class RowFetchTests: GRDBTestCase { try test(Row.fetchCursor(db, sql, adapter: adapter)) try test(Row.fetchCursor(statement, adapter: adapter)) try test(Row.fetchCursor(db, SQLRequest(sql, adapter: adapter))) - try test(SQLRequest(sql, adapter: adapter).fetching(Row.self).fetchCursor(db)) + try test(SQLRequest(sql, adapter: adapter).asRequest(of: Row.self).fetchCursor(db)) } } } @@ -71,7 +71,7 @@ class RowFetchTests: GRDBTestCase { try test(Row.fetchCursor(db, sql), sql: sql) try test(Row.fetchCursor(db.makeSelectStatement(sql)), sql: sql) try test(Row.fetchCursor(db, SQLRequest(sql)), sql: sql) - try test(SQLRequest(sql).fetching(Row.self).fetchCursor(db), sql: sql) + try test(SQLRequest(sql).asRequest(of: Row.self).fetchCursor(db), sql: sql) } do { let sql = "SELECT 0, throw(), NULL" @@ -79,7 +79,7 @@ class RowFetchTests: GRDBTestCase { try test(Row.fetchCursor(db, sql, adapter: adapter), sql: sql) try test(Row.fetchCursor(db.makeSelectStatement(sql), adapter: adapter), sql: sql) try test(Row.fetchCursor(db, SQLRequest(sql, adapter: adapter)), sql: sql) - try test(SQLRequest(sql, adapter: adapter).fetching(Row.self).fetchCursor(db), sql: sql) + try test(SQLRequest(sql, adapter: adapter).asRequest(of: Row.self).fetchCursor(db), sql: sql) } } } @@ -103,7 +103,7 @@ class RowFetchTests: GRDBTestCase { try test(Row.fetchCursor(db, sql), sql: sql) try test(Row.fetchCursor(db.makeSelectStatement(sql)), sql: sql) try test(Row.fetchCursor(db, SQLRequest(sql)), sql: sql) - try test(SQLRequest(sql).fetching(Row.self).fetchCursor(db), sql: sql) + try test(SQLRequest(sql).asRequest(of: Row.self).fetchCursor(db), sql: sql) } do { let sql = "SELECT * FROM nonExistingTable" @@ -111,7 +111,7 @@ class RowFetchTests: GRDBTestCase { try test(Row.fetchCursor(db, sql, adapter: adapter), sql: sql) try test(Row.fetchCursor(db.makeSelectStatement(sql), adapter: adapter), sql: sql) try test(Row.fetchCursor(db, SQLRequest(sql, adapter: adapter)), sql: sql) - try test(SQLRequest(sql, adapter: adapter).fetching(Row.self).fetchCursor(db), sql: sql) + try test(SQLRequest(sql, adapter: adapter).asRequest(of: Row.self).fetchCursor(db), sql: sql) } } } @@ -129,7 +129,7 @@ class RowFetchTests: GRDBTestCase { try test(Row.fetchAll(db, sql)) try test(Row.fetchAll(statement)) try test(Row.fetchAll(db, SQLRequest(sql))) - try test(SQLRequest(sql).fetching(Row.self).fetchAll(db)) + try test(SQLRequest(sql).asRequest(of: Row.self).fetchAll(db)) } do { let sql = "SELECT 0 AS firstName, 'Arthur' AS firstName, 'Martin' AS lastName UNION ALL SELECT 0, 'Barbara', 'Gourde'" @@ -138,7 +138,7 @@ class RowFetchTests: GRDBTestCase { try test(Row.fetchAll(db, sql, adapter: adapter)) try test(Row.fetchAll(statement, adapter: adapter)) try test(Row.fetchAll(db, SQLRequest(sql, adapter: adapter))) - try test(SQLRequest(sql, adapter: adapter).fetching(Row.self).fetchAll(db)) + try test(SQLRequest(sql, adapter: adapter).asRequest(of: Row.self).fetchAll(db)) } } } @@ -164,7 +164,7 @@ class RowFetchTests: GRDBTestCase { try test(Row.fetchAll(db, sql), sql: sql) try test(Row.fetchAll(db.makeSelectStatement(sql)), sql: sql) try test(Row.fetchAll(db, SQLRequest(sql)), sql: sql) - try test(SQLRequest(sql).fetching(Row.self).fetchAll(db), sql: sql) + try test(SQLRequest(sql).asRequest(of: Row.self).fetchAll(db), sql: sql) } do { let sql = "SELECT 0, throw()" @@ -172,7 +172,7 @@ class RowFetchTests: GRDBTestCase { try test(Row.fetchAll(db, sql, adapter: adapter), sql: sql) try test(Row.fetchAll(db.makeSelectStatement(sql), adapter: adapter), sql: sql) try test(Row.fetchAll(db, SQLRequest(sql, adapter: adapter)), sql: sql) - try test(SQLRequest(sql, adapter: adapter).fetching(Row.self).fetchAll(db), sql: sql) + try test(SQLRequest(sql, adapter: adapter).asRequest(of: Row.self).fetchAll(db), sql: sql) } } } @@ -196,7 +196,7 @@ class RowFetchTests: GRDBTestCase { try test(Row.fetchAll(db, sql), sql: sql) try test(Row.fetchAll(db.makeSelectStatement(sql)), sql: sql) try test(Row.fetchAll(db, SQLRequest(sql)), sql: sql) - try test(SQLRequest(sql).fetching(Row.self).fetchAll(db), sql: sql) + try test(SQLRequest(sql).asRequest(of: Row.self).fetchAll(db), sql: sql) } do { let sql = "SELECT * FROM nonExistingTable" @@ -204,7 +204,7 @@ class RowFetchTests: GRDBTestCase { try test(Row.fetchAll(db, sql, adapter: adapter), sql: sql) try test(Row.fetchAll(db.makeSelectStatement(sql), adapter: adapter), sql: sql) try test(Row.fetchAll(db, SQLRequest(sql, adapter: adapter)), sql: sql) - try test(SQLRequest(sql, adapter: adapter).fetching(Row.self).fetchAll(db), sql: sql) + try test(SQLRequest(sql, adapter: adapter).asRequest(of: Row.self).fetchAll(db), sql: sql) } } } @@ -222,7 +222,7 @@ class RowFetchTests: GRDBTestCase { try test(Row.fetchOne(db, sql)) try test(Row.fetchOne(statement)) try test(Row.fetchOne(db, SQLRequest(sql))) - try test(SQLRequest(sql).fetching(Row.self).fetchOne(db)) + try test(SQLRequest(sql).asRequest(of: Row.self).fetchOne(db)) } do { let sql = "SELECT 0, 1 WHERE 0" @@ -231,7 +231,7 @@ class RowFetchTests: GRDBTestCase { try test(Row.fetchOne(db, sql, adapter: adapter)) try test(Row.fetchOne(statement, adapter: adapter)) try test(Row.fetchOne(db, SQLRequest(sql, adapter: adapter))) - try test(SQLRequest(sql, adapter: adapter).fetching(Row.self).fetchOne(db)) + try test(SQLRequest(sql, adapter: adapter).asRequest(of: Row.self).fetchOne(db)) } } do { @@ -245,7 +245,7 @@ class RowFetchTests: GRDBTestCase { try test(Row.fetchOne(db, sql)) try test(Row.fetchOne(statement)) try test(Row.fetchOne(db, SQLRequest(sql))) - try test(SQLRequest(sql).fetching(Row.self).fetchOne(db)) + try test(SQLRequest(sql).asRequest(of: Row.self).fetchOne(db)) } do { let sql = "SELECT 0 AS firstName, 'Arthur' AS firstName, 'Martin' AS lastName" @@ -254,7 +254,7 @@ class RowFetchTests: GRDBTestCase { try test(Row.fetchOne(db, sql, adapter: adapter)) try test(Row.fetchOne(statement, adapter: adapter)) try test(Row.fetchOne(db, SQLRequest(sql, adapter: adapter))) - try test(SQLRequest(sql, adapter: adapter).fetching(Row.self).fetchOne(db)) + try test(SQLRequest(sql, adapter: adapter).asRequest(of: Row.self).fetchOne(db)) } } } @@ -281,7 +281,7 @@ class RowFetchTests: GRDBTestCase { try test(Row.fetchOne(db, sql), sql: sql) try test(Row.fetchOne(db.makeSelectStatement(sql)), sql: sql) try test(Row.fetchOne(db, SQLRequest(sql)), sql: sql) - try test(SQLRequest(sql).fetching(Row.self).fetchOne(db), sql: sql) + try test(SQLRequest(sql).asRequest(of: Row.self).fetchOne(db), sql: sql) } do { let sql = "SELECT 0, throw()" @@ -289,7 +289,7 @@ class RowFetchTests: GRDBTestCase { try test(Row.fetchOne(db, sql, adapter: adapter), sql: sql) try test(Row.fetchOne(db.makeSelectStatement(sql), adapter: adapter), sql: sql) try test(Row.fetchOne(db, SQLRequest(sql, adapter: adapter)), sql: sql) - try test(SQLRequest(sql, adapter: adapter).fetching(Row.self).fetchOne(db), sql: sql) + try test(SQLRequest(sql, adapter: adapter).asRequest(of: Row.self).fetchOne(db), sql: sql) } } } @@ -313,7 +313,7 @@ class RowFetchTests: GRDBTestCase { try test(Row.fetchOne(db, sql), sql: sql) try test(Row.fetchOne(db.makeSelectStatement(sql)), sql: sql) try test(Row.fetchOne(db, SQLRequest(sql)), sql: sql) - try test(SQLRequest(sql).fetching(Row.self).fetchOne(db), sql: sql) + try test(SQLRequest(sql).asRequest(of: Row.self).fetchOne(db), sql: sql) } do { let sql = "SELECT * FROM nonExistingTable" @@ -321,7 +321,7 @@ class RowFetchTests: GRDBTestCase { try test(Row.fetchOne(db, sql, adapter: adapter), sql: sql) try test(Row.fetchOne(db.makeSelectStatement(sql), adapter: adapter), sql: sql) try test(Row.fetchOne(db, SQLRequest(sql, adapter: adapter)), sql: sql) - try test(SQLRequest(sql, adapter: adapter).fetching(Row.self).fetchOne(db), sql: sql) + try test(SQLRequest(sql, adapter: adapter).asRequest(of: Row.self).fetchOne(db), sql: sql) } } } diff --git a/Tests/GRDBTests/StatementColumnConvertibleFetchTests.swift b/Tests/GRDBTests/StatementColumnConvertibleFetchTests.swift index 7aa3e833c..1cc75e744 100644 --- a/Tests/GRDBTests/StatementColumnConvertibleFetchTests.swift +++ b/Tests/GRDBTests/StatementColumnConvertibleFetchTests.swift @@ -99,7 +99,7 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase { try test(Fetched.fetchCursor(db, sql)) try test(Fetched.fetchCursor(statement)) try test(Fetched.fetchCursor(db, SQLRequest(sql))) - try test(SQLRequest(sql).fetching(Fetched.self).fetchCursor(db)) + try test(SQLRequest(sql).asRequest(of: Fetched.self).fetchCursor(db)) } do { let sql = "SELECT 0, 1 UNION ALL SELECT 0, 2" @@ -108,7 +108,7 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase { try test(Fetched.fetchCursor(db, sql, adapter: adapter)) try test(Fetched.fetchCursor(statement, adapter: adapter)) try test(Fetched.fetchCursor(db, SQLRequest(sql, adapter: adapter))) - try test(SQLRequest(sql, adapter: adapter).fetching(Fetched.self).fetchCursor(db)) + try test(SQLRequest(sql, adapter: adapter).asRequest(of: Fetched.self).fetchCursor(db)) } } } @@ -143,7 +143,7 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase { try test(Fetched.fetchCursor(db, sql), sql: sql) try test(Fetched.fetchCursor(db.makeSelectStatement(sql)), sql: sql) try test(Fetched.fetchCursor(db, SQLRequest(sql)), sql: sql) - try test(SQLRequest(sql).fetching(Fetched.self).fetchCursor(db), sql: sql) + try test(SQLRequest(sql).asRequest(of: Fetched.self).fetchCursor(db), sql: sql) } do { let sql = "SELECT 0, throw()" @@ -151,7 +151,7 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase { try test(Fetched.fetchCursor(db, sql, adapter: adapter), sql: sql) try test(Fetched.fetchCursor(db.makeSelectStatement(sql), adapter: adapter), sql: sql) try test(Fetched.fetchCursor(db, SQLRequest(sql, adapter: adapter)), sql: sql) - try test(SQLRequest(sql, adapter: adapter).fetching(Fetched.self).fetchCursor(db), sql: sql) + try test(SQLRequest(sql, adapter: adapter).asRequest(of: Fetched.self).fetchCursor(db), sql: sql) } } } @@ -175,7 +175,7 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase { try test(Fetched.fetchCursor(db, sql), sql: sql) try test(Fetched.fetchCursor(db.makeSelectStatement(sql)), sql: sql) try test(Fetched.fetchCursor(db, SQLRequest(sql)), sql: sql) - try test(SQLRequest(sql).fetching(Fetched.self).fetchCursor(db), sql: sql) + try test(SQLRequest(sql).asRequest(of: Fetched.self).fetchCursor(db), sql: sql) } do { let sql = "SELECT * FROM nonExistingTable" @@ -183,7 +183,7 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase { try test(Fetched.fetchCursor(db, sql, adapter: adapter), sql: sql) try test(Fetched.fetchCursor(db.makeSelectStatement(sql), adapter: adapter), sql: sql) try test(Fetched.fetchCursor(db, SQLRequest(sql, adapter: adapter)), sql: sql) - try test(SQLRequest(sql, adapter: adapter).fetching(Fetched.self).fetchCursor(db), sql: sql) + try test(SQLRequest(sql, adapter: adapter).asRequest(of: Fetched.self).fetchCursor(db), sql: sql) } } } @@ -201,7 +201,7 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase { try test(Fetched.fetchAll(db, sql)) try test(Fetched.fetchAll(statement)) try test(Fetched.fetchAll(db, SQLRequest(sql))) - try test(SQLRequest(sql).fetching(Fetched.self).fetchAll(db)) + try test(SQLRequest(sql).asRequest(of: Fetched.self).fetchAll(db)) } do { let sql = "SELECT 0, 1 UNION ALL SELECT 0, 2" @@ -210,7 +210,7 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase { try test(Fetched.fetchAll(db, sql, adapter: adapter)) try test(Fetched.fetchAll(statement, adapter: adapter)) try test(Fetched.fetchAll(db, SQLRequest(sql, adapter: adapter))) - try test(SQLRequest(sql, adapter: adapter).fetching(Fetched.self).fetchAll(db)) + try test(SQLRequest(sql, adapter: adapter).asRequest(of: Fetched.self).fetchAll(db)) } } } @@ -236,7 +236,7 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase { try test(Fetched.fetchAll(db, sql), sql: sql) try test(Fetched.fetchAll(db.makeSelectStatement(sql)), sql: sql) try test(Fetched.fetchAll(db, SQLRequest(sql)), sql: sql) - try test(SQLRequest(sql).fetching(Fetched.self).fetchAll(db), sql: sql) + try test(SQLRequest(sql).asRequest(of: Fetched.self).fetchAll(db), sql: sql) } do { let sql = "SELECT 0, throw()" @@ -244,7 +244,7 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase { try test(Fetched.fetchAll(db, sql, adapter: adapter), sql: sql) try test(Fetched.fetchAll(db.makeSelectStatement(sql), adapter: adapter), sql: sql) try test(Fetched.fetchAll(db, SQLRequest(sql, adapter: adapter)), sql: sql) - try test(SQLRequest(sql, adapter: adapter).fetching(Fetched.self).fetchAll(db), sql: sql) + try test(SQLRequest(sql, adapter: adapter).asRequest(of: Fetched.self).fetchAll(db), sql: sql) } } } @@ -268,7 +268,7 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase { try test(Fetched.fetchAll(db, sql), sql: sql) try test(Fetched.fetchAll(db.makeSelectStatement(sql)), sql: sql) try test(Fetched.fetchAll(db, SQLRequest(sql)), sql: sql) - try test(SQLRequest(sql).fetching(Fetched.self).fetchAll(db), sql: sql) + try test(SQLRequest(sql).asRequest(of: Fetched.self).fetchAll(db), sql: sql) } do { let sql = "SELECT * FROM nonExistingTable" @@ -276,7 +276,7 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase { try test(Fetched.fetchAll(db, sql, adapter: adapter), sql: sql) try test(Fetched.fetchAll(db.makeSelectStatement(sql), adapter: adapter), sql: sql) try test(Fetched.fetchAll(db, SQLRequest(sql, adapter: adapter)), sql: sql) - try test(SQLRequest(sql, adapter: adapter).fetching(Fetched.self).fetchAll(db), sql: sql) + try test(SQLRequest(sql, adapter: adapter).asRequest(of: Fetched.self).fetchAll(db), sql: sql) } } } @@ -294,7 +294,7 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase { try test(Fetched.fetchOne(db, sql)) try test(Fetched.fetchOne(statement)) try test(Fetched.fetchOne(db, SQLRequest(sql))) - try test(SQLRequest(sql).fetching(Fetched.self).fetchOne(db)) + try test(SQLRequest(sql).asRequest(of: Fetched.self).fetchOne(db)) } do { let sql = "SELECT 0, 1 WHERE 0" @@ -303,7 +303,7 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase { try test(Fetched.fetchOne(db, sql, adapter: adapter)) try test(Fetched.fetchOne(statement, adapter: adapter)) try test(Fetched.fetchOne(db, SQLRequest(sql, adapter: adapter))) - try test(SQLRequest(sql, adapter: adapter).fetching(Fetched.self).fetchOne(db)) + try test(SQLRequest(sql, adapter: adapter).asRequest(of: Fetched.self).fetchOne(db)) } } do { @@ -316,7 +316,7 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase { try test(Fetched.fetchOne(db, sql)) try test(Fetched.fetchOne(statement)) try test(Fetched.fetchOne(db, SQLRequest(sql))) - try test(SQLRequest(sql).fetching(Fetched.self).fetchOne(db)) + try test(SQLRequest(sql).asRequest(of: Fetched.self).fetchOne(db)) } do { let sql = "SELECT 0, NULL" @@ -325,7 +325,7 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase { try test(Fetched.fetchOne(db, sql, adapter: adapter)) try test(Fetched.fetchOne(statement, adapter: adapter)) try test(Fetched.fetchOne(db, SQLRequest(sql, adapter: adapter))) - try test(SQLRequest(sql, adapter: adapter).fetching(Fetched.self).fetchOne(db)) + try test(SQLRequest(sql, adapter: adapter).asRequest(of: Fetched.self).fetchOne(db)) } } do { @@ -338,7 +338,7 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase { try test(Fetched.fetchOne(db, sql)) try test(Fetched.fetchOne(statement)) try test(Fetched.fetchOne(db, SQLRequest(sql))) - try test(SQLRequest(sql).fetching(Fetched.self).fetchOne(db)) + try test(SQLRequest(sql).asRequest(of: Fetched.self).fetchOne(db)) } do { let sql = "SELECT 0, 1" @@ -347,7 +347,7 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase { try test(Fetched.fetchOne(db, sql, adapter: adapter)) try test(Fetched.fetchOne(statement, adapter: adapter)) try test(Fetched.fetchOne(db, SQLRequest(sql, adapter: adapter))) - try test(SQLRequest(sql, adapter: adapter).fetching(Fetched.self).fetchOne(db)) + try test(SQLRequest(sql, adapter: adapter).asRequest(of: Fetched.self).fetchOne(db)) } } } @@ -374,7 +374,7 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase { try test(Fetched.fetchOne(db, sql), sql: sql) try test(Fetched.fetchOne(db.makeSelectStatement(sql)), sql: sql) try test(Fetched.fetchOne(db, SQLRequest(sql)), sql: sql) - try test(SQLRequest(sql).fetching(Fetched.self).fetchOne(db), sql: sql) + try test(SQLRequest(sql).asRequest(of: Fetched.self).fetchOne(db), sql: sql) } do { let sql = "SELECT 0, throw()" @@ -382,7 +382,7 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase { try test(Fetched.fetchOne(db, sql, adapter: adapter), sql: sql) try test(Fetched.fetchOne(db.makeSelectStatement(sql), adapter: adapter), sql: sql) try test(Fetched.fetchOne(db, SQLRequest(sql, adapter: adapter)), sql: sql) - try test(SQLRequest(sql, adapter: adapter).fetching(Fetched.self).fetchOne(db), sql: sql) + try test(SQLRequest(sql, adapter: adapter).asRequest(of: Fetched.self).fetchOne(db), sql: sql) } } } @@ -406,7 +406,7 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase { try test(Fetched.fetchOne(db, sql), sql: sql) try test(Fetched.fetchOne(db.makeSelectStatement(sql)), sql: sql) try test(Fetched.fetchOne(db, SQLRequest(sql)), sql: sql) - try test(SQLRequest(sql).fetching(Fetched.self).fetchOne(db), sql: sql) + try test(SQLRequest(sql).asRequest(of: Fetched.self).fetchOne(db), sql: sql) } do { let sql = "SELECT * FROM nonExistingTable" @@ -414,7 +414,7 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase { try test(Fetched.fetchOne(db, sql, adapter: adapter), sql: sql) try test(Fetched.fetchOne(db.makeSelectStatement(sql), adapter: adapter), sql: sql) try test(Fetched.fetchOne(db, SQLRequest(sql, adapter: adapter)), sql: sql) - try test(SQLRequest(sql, adapter: adapter).fetching(Fetched.self).fetchOne(db), sql: sql) + try test(SQLRequest(sql, adapter: adapter).asRequest(of: Fetched.self).fetchOne(db), sql: sql) } } } @@ -437,7 +437,7 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase { try test(Optional.fetchCursor(db, sql)) try test(Optional.fetchCursor(statement)) try test(Optional.fetchCursor(db, SQLRequest(sql))) - try test(SQLRequest(sql).fetching(Optional.self).fetchCursor(db)) + try test(SQLRequest(sql).asRequest(of: Optional.self).fetchCursor(db)) } do { let sql = "SELECT 0, 1 UNION ALL SELECT 0, NULL" @@ -446,7 +446,7 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase { try test(Optional.fetchCursor(db, sql, adapter: adapter)) try test(Optional.fetchCursor(statement, adapter: adapter)) try test(Optional.fetchCursor(db, SQLRequest(sql, adapter: adapter))) - try test(SQLRequest(sql, adapter: adapter).fetching(Optional.self).fetchCursor(db)) + try test(SQLRequest(sql, adapter: adapter).asRequest(of: Optional.self).fetchCursor(db)) } } } @@ -470,7 +470,7 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase { try test(Optional.fetchCursor(db, sql), sql: sql) try test(Optional.fetchCursor(db.makeSelectStatement(sql)), sql: sql) try test(Optional.fetchCursor(db, SQLRequest(sql)), sql: sql) - try test(SQLRequest(sql).fetching(Optional.self).fetchCursor(db), sql: sql) + try test(SQLRequest(sql).asRequest(of: Optional.self).fetchCursor(db), sql: sql) } do { let sql = "SELECT * FROM nonExistingTable" @@ -478,7 +478,7 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase { try test(Optional.fetchCursor(db, sql, adapter: adapter), sql: sql) try test(Optional.fetchCursor(db.makeSelectStatement(sql), adapter: adapter), sql: sql) try test(Optional.fetchCursor(db, SQLRequest(sql, adapter: adapter)), sql: sql) - try test(SQLRequest(sql, adapter: adapter).fetching(Optional.self).fetchCursor(db), sql: sql) + try test(SQLRequest(sql, adapter: adapter).asRequest(of: Optional.self).fetchCursor(db), sql: sql) } } } @@ -498,7 +498,7 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase { try test(Optional.fetchAll(db, sql)) try test(Optional.fetchAll(statement)) try test(Optional.fetchAll(db, SQLRequest(sql))) - try test(SQLRequest(sql).fetching(Optional.self).fetchAll(db)) + try test(SQLRequest(sql).asRequest(of: Optional.self).fetchAll(db)) } do { let sql = "SELECT 0, 1 UNION ALL SELECT 0, NULL" @@ -507,7 +507,7 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase { try test(Optional.fetchAll(db, sql, adapter: adapter)) try test(Optional.fetchAll(statement, adapter: adapter)) try test(Optional.fetchAll(db, SQLRequest(sql, adapter: adapter))) - try test(SQLRequest(sql, adapter: adapter).fetching(Optional.self).fetchAll(db)) + try test(SQLRequest(sql, adapter: adapter).asRequest(of: Optional.self).fetchAll(db)) } } } @@ -533,7 +533,7 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase { try test(Optional.fetchAll(db, sql), sql: sql) try test(Optional.fetchAll(db.makeSelectStatement(sql)), sql: sql) try test(Optional.fetchAll(db, SQLRequest(sql)), sql: sql) - try test(SQLRequest(sql).fetching(Optional.self).fetchAll(db), sql: sql) + try test(SQLRequest(sql).asRequest(of: Optional.self).fetchAll(db), sql: sql) } do { let sql = "SELECT 0, throw()" @@ -541,7 +541,7 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase { try test(Optional.fetchAll(db, sql, adapter: adapter), sql: sql) try test(Optional.fetchAll(db.makeSelectStatement(sql), adapter: adapter), sql: sql) try test(Optional.fetchAll(db, SQLRequest(sql, adapter: adapter)), sql: sql) - try test(SQLRequest(sql, adapter: adapter).fetching(Optional.self).fetchAll(db), sql: sql) + try test(SQLRequest(sql, adapter: adapter).asRequest(of: Optional.self).fetchAll(db), sql: sql) } } } @@ -565,7 +565,7 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase { try test(Optional.fetchAll(db, sql), sql: sql) try test(Optional.fetchAll(db.makeSelectStatement(sql)), sql: sql) try test(Optional.fetchAll(db, SQLRequest(sql)), sql: sql) - try test(SQLRequest(sql).fetching(Optional.self).fetchAll(db), sql: sql) + try test(SQLRequest(sql).asRequest(of: Optional.self).fetchAll(db), sql: sql) } do { let sql = "SELECT * FROM nonExistingTable" @@ -573,7 +573,7 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase { try test(Optional.fetchAll(db, sql, adapter: adapter), sql: sql) try test(Optional.fetchAll(db.makeSelectStatement(sql), adapter: adapter), sql: sql) try test(Optional.fetchAll(db, SQLRequest(sql, adapter: adapter)), sql: sql) - try test(SQLRequest(sql, adapter: adapter).fetching(Optional.self).fetchAll(db), sql: sql) + try test(SQLRequest(sql, adapter: adapter).asRequest(of: Optional.self).fetchAll(db), sql: sql) } } }