mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-25 04:07:47 +00:00
Merge pull request #311 from groue/GRDB3-FetchRequest
Rename TypedRequest to FetchRequest, drop Request
This commit is contained in:
35 files changed
+1209
-1570
No files matched your search
@@ -1,6 +1,104 @@
|
||||
Release Notes
|
||||
=============
|
||||
|
||||
## Next Version
|
||||
|
||||
### Breaking Changes
|
||||
|
||||
- `Request` and `TypedRequest` protocols have been merged into `FetchRequest`.
|
||||
|
||||
### API diff
|
||||
|
||||
FetchRequest
|
||||
|
||||
```diff
|
||||
+protocol FetchRequest {
|
||||
+ associatedtype RowDecoder
|
||||
+ func prepare(_ db: Database) throws -> (SelectStatement, RowAdapter?)
|
||||
+ func fetchCount(_ db: Database) throws -> Int
|
||||
+ func fetchedRegion(_ db: Database) throws -> DatabaseRegion
|
||||
+}
|
||||
+extension FetchRequest {
|
||||
+ func fetchCount(_ db: Database) throws -> Int
|
||||
+ func fetchedRegion(_ db: Database) throws -> DatabaseRegion
|
||||
+ func asRequest<T>(of type: T.Type) -> AnyFetchRequest<T>
|
||||
+ func adapted(_ adapter: @escaping (Database) throws -> RowAdapter) -> AdaptedFetchRequest<Self>
|
||||
+}
|
||||
+struct AdaptedFetchRequest<Base: FetchRequest> : FetchRequest {
|
||||
+ typealias RowDecoder = Base.RowDecoder
|
||||
+}
|
||||
+struct AnyFetchRequest<T> : FetchRequest {
|
||||
+ typealias RowDecoder = T
|
||||
+ init<Request: FetchRequest>(_ request: Request)
|
||||
+ init(_ prepare: @escaping (Database) throws -> (SelectStatement, RowAdapter?))
|
||||
+}
|
||||
+struct SQLRequest<T> : FetchRequest {
|
||||
+ typealias RowDecoder = T
|
||||
+ let sql: String
|
||||
+ let arguments: StatementArguments?
|
||||
+ let adapter: RowAdapter?
|
||||
+ init(_ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil, cached: Bool = false)
|
||||
+ init<Request: FetchRequest>(_ db: Database, request: Request, cached: Bool = false) throws where Request.RowDecoder == RowDecoder
|
||||
+}
|
||||
|
||||
+extension FetchRequest where RowDecoder: DatabaseValueConvertible {
|
||||
+ func fetchCursor(_ db: Database) throws -> DatabaseValueCursor<RowDecoder>
|
||||
+ func fetchAll(_ db: Database) throws -> [RowDecoder]
|
||||
+ func fetchOne(_ db: Database) throws -> RowDecoder?
|
||||
+
|
||||
}
|
||||
+extension FetchRequest where RowDecoder: _OptionalProtocol, RowDecoder._Wrapped: DatabaseValueConvertible
|
||||
+ func fetchCursor(_ db: Database) throws -> NullableDatabaseValueCursor<RowDecoder._Wrapped>
|
||||
+ func fetchAll(_ db: Database) throws -> [RowDecoder._Wrapped?]
|
||||
+}
|
||||
|
||||
+extension FetchRequest where RowDecoder: Row {
|
||||
+ func fetchCursor(_ db: Database) throws -> RowCursor
|
||||
+ func fetchAll(_ db: Database) throws -> [Row]
|
||||
+ func fetchOne(_ db: Database) throws -> Row?
|
||||
+}
|
||||
|
||||
+extension FetchRequest where RowDecoder: RowConvertible {
|
||||
+ func fetchCursor(_ db: Database) throws -> RecordCursor<RowDecoder>
|
||||
+ func fetchAll(_ db: Database) throws -> [RowDecoder]
|
||||
+ func fetchOne(_ db: Database) throws -> RowDecoder?
|
||||
+}
|
||||
|
||||
-protocol Request { }
|
||||
-struct AdaptedRequest : Request { }
|
||||
-struct AnyRequest : Request { }
|
||||
-struct SQLRequest : Request { }
|
||||
-protocol TypedRequest : Request { }
|
||||
-struct AdaptedTypedRequest<Base: TypedRequest> : TypedRequest { }
|
||||
-struct AnyTypedRequest<T> : TypedRequest { }
|
||||
|
||||
-extension DatabaseValueConvertible {
|
||||
- static func fetchCursor(_ db: Database, _ request: Request) throws -> DatabaseValueCursor<Self>
|
||||
- static func fetchAll(_ db: Database, _ request: Request) throws -> [Self]
|
||||
- static func fetchOne(_ db: Database, _ request: Request) throws -> Self?
|
||||
-}
|
||||
|
||||
-extension Optional where Wrapped: DatabaseValueConvertible {
|
||||
- static func fetchCursor(_ db: Database, _ request: Request) throws -> NullableDatabaseValueCursor<Wrapped>
|
||||
- static func fetchAll(_ db: Database, _ request: Request) throws -> [Wrapped?]
|
||||
-}
|
||||
|
||||
-extension Row {
|
||||
- static func fetchCursor(_ db: Database, _ request: Request) throws -> RowCursor
|
||||
- static func fetchAll(_ db: Database, _ request: Request) throws -> [Row]
|
||||
- static func fetchOne(_ db: Database, _ request: Request) throws -> Row?
|
||||
-}
|
||||
|
||||
-extension RowConvertible {
|
||||
- static func fetchCursor(_ db: Database, _ request: Request) throws -> RecordCursor<Self>
|
||||
- static func fetchAll(_ db: Database, _ request: Request) throws -> [Self]
|
||||
- static func fetchOne(_ db: Database, _ request: Request) throws -> Self?
|
||||
-}
|
||||
|
||||
-extension QueryInterfaceRequest : TypedRequest { }
|
||||
+extension QueryInterfaceRequest : FetchRequest { }
|
||||
```
|
||||
|
||||
## 2.9.0
|
||||
|
||||
Released February 25, 2018 • [diff](https://github.com/groue/GRDB.swift/compare/v2.8.0...v2.9.0)
|
||||
|
||||
@@ -175,7 +175,7 @@ For further information about GRDB concurrency, check its detailed [Concurrency
|
||||
|
||||
SQL is a weird language. Born in the 70s, easy to [misuse](https://xkcd.com/327/), feared by some developers, despised by others, and yet wonderfully concise and powerful.
|
||||
|
||||
GRDB provides high-level record methods that generate SQL for you:
|
||||
GRDB records can generate SQL for you:
|
||||
|
||||
```swift
|
||||
// SELECT * FROM players ORDER BY score DESC LIMIT 10
|
||||
@@ -196,7 +196,7 @@ let exAequoCount: Int = try Player
|
||||
.fetchCount(db)
|
||||
```
|
||||
|
||||
But you can *always* switch to SQL when you want to:
|
||||
But you can always switch to SQL when you want to:
|
||||
|
||||
```swift
|
||||
let bestPlayers: [Player] = try Player.fetchAll(db, """
|
||||
@@ -212,26 +212,14 @@ let exAequoCount: Int? = try Int.fetchOne(db, """
|
||||
""", arguments: [maximumScore])
|
||||
```
|
||||
|
||||
SQL is also welcome in high-level database observation tools like [FetchedRecordsController] and [RxGRDB]:
|
||||
In performance-critical sections, you may want to deal with raw database rows, and fetch [lazy cursors](https://github.com/groue/GRDB.swift/blob/master/README.md#cursors) instead of arrays:
|
||||
|
||||
```swift
|
||||
SQLRequest("SELECT * FROM players ORDER BY score DESC LIMIT 10")
|
||||
.asRequest(of: Player.self)
|
||||
.rx
|
||||
.fetchAll(in: dbQueue)
|
||||
.subscribe(onNext: { players: [Player] in
|
||||
print("Best 10 players have changed")
|
||||
})
|
||||
```
|
||||
|
||||
You can of course deal with raw database rows, and fetch [lazy cursors](https://github.com/groue/GRDB.swift/blob/master/README.md#cursors) instead of arrays:
|
||||
|
||||
```swift
|
||||
let rows = try Row.fetchCursor(db, "SELECT * FROM players")
|
||||
let rows = try Row.fetchCursor(db, "SELECT id, name, score FROM players")
|
||||
while let row = try rows.next() {
|
||||
let id: Int64 = row["id"]
|
||||
let name: String = row["name"]
|
||||
let score: Int = row["score"]
|
||||
let id: Int64 = row[0]
|
||||
let name: String = row[1]
|
||||
let score: Int = row[2]
|
||||
}
|
||||
```
|
||||
|
||||
@@ -239,15 +227,22 @@ When you feel like your code clarity would be enhanced by hiding your custom SQL
|
||||
|
||||
```swift
|
||||
extension Player {
|
||||
static func customRequest(...) -> AnyTypedRequest<Player> {
|
||||
return SQLRequest("""
|
||||
SELECT ...
|
||||
""", arguments: ...)
|
||||
.asRequestOf(Player.self)
|
||||
static func customRequest(...) -> SQLRequest<Player> {
|
||||
return SQLRequest<Player>("SELECT ...", arguments: ...)
|
||||
}
|
||||
}
|
||||
|
||||
let players = Player.customRequest(...).fetchAll(db)
|
||||
let players = try Player.customRequest(...).fetchAll(db)
|
||||
```
|
||||
|
||||
Those custom requests are welcome in database observation tools like [FetchedRecordsController] and [RxGRDB]:
|
||||
|
||||
```swift
|
||||
Player.customRequest(...)
|
||||
.rx.fetchAll(in: dbQueue)
|
||||
.subscribe(onNext: { players: [Player] in
|
||||
print("Players have changed")
|
||||
})
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
@@ -27,8 +27,8 @@
|
||||
5605F1881C69111300235C62 /* DatabaseRegionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5605F1861C69111300235C62 /* DatabaseRegionTests.swift */; };
|
||||
5605F18D1C6B1A8700235C62 /* SQLCollatedExpression.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5605F1891C6B1A8700235C62 /* SQLCollatedExpression.swift */; };
|
||||
5605F18E1C6B1A8700235C62 /* SQLCollatedExpression.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5605F1891C6B1A8700235C62 /* SQLCollatedExpression.swift */; };
|
||||
5605F1931C6B1A8700235C62 /* QueryInterfaceSelectQueryDefinition.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5605F18C1C6B1A8700235C62 /* QueryInterfaceSelectQueryDefinition.swift */; };
|
||||
5605F1941C6B1A8700235C62 /* QueryInterfaceSelectQueryDefinition.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5605F18C1C6B1A8700235C62 /* QueryInterfaceSelectQueryDefinition.swift */; };
|
||||
5605F1931C6B1A8700235C62 /* QueryInterfaceQuery.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5605F18C1C6B1A8700235C62 /* QueryInterfaceQuery.swift */; };
|
||||
5605F1941C6B1A8700235C62 /* QueryInterfaceQuery.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5605F18C1C6B1A8700235C62 /* QueryInterfaceQuery.swift */; };
|
||||
56071A411DB54ED000CA6E47 /* FetchedRecordsControllerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B15D0A1CD4C35100A24C8B /* FetchedRecordsControllerTests.swift */; };
|
||||
5607EFD41BB827FD00605DE3 /* TransactionObserverTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5607EFD21BB8254800605DE3 /* TransactionObserverTests.swift */; };
|
||||
560A37A41C8F625000949E71 /* DatabasePool.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560A37A31C8F625000949E71 /* DatabasePool.swift */; };
|
||||
@@ -113,8 +113,8 @@
|
||||
563363D11C943D13000BE133 /* DatabasePoolReleaseMemoryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563363CF1C943D13000BE133 /* DatabasePoolReleaseMemoryTests.swift */; };
|
||||
563363D61C94484E000BE133 /* DatabaseQueueReleaseMemoryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563363D41C94484E000BE133 /* DatabaseQueueReleaseMemoryTests.swift */; };
|
||||
5634B10A1CF9B970005360B9 /* TransactionObserverSavepointsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5634B1061CF9B970005360B9 /* TransactionObserverSavepointsTests.swift */; };
|
||||
5636E9BC1D22574100B9B05F /* Request.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5636E9BB1D22574100B9B05F /* Request.swift */; };
|
||||
5636E9BF1D22574100B9B05F /* Request.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5636E9BB1D22574100B9B05F /* Request.swift */; };
|
||||
5636E9BC1D22574100B9B05F /* FetchRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5636E9BB1D22574100B9B05F /* FetchRequest.swift */; };
|
||||
5636E9BF1D22574100B9B05F /* FetchRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5636E9BB1D22574100B9B05F /* FetchRequest.swift */; };
|
||||
56439B331F4CA1DC0066043F /* FMDatabase.m in Sources */ = {isa = PBXBuildFile; fileRef = 56BB86191BA988F2001F9168 /* FMDatabase.m */; };
|
||||
56439B341F4CA1DC0066043F /* InsertRecordClassTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56BB86121BA9886D001F9168 /* InsertRecordClassTests.swift */; };
|
||||
56439B351F4CA1DC0066043F /* FMDatabaseAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 56BB861B1BA988F2001F9168 /* FMDatabaseAdditions.m */; };
|
||||
@@ -159,7 +159,7 @@
|
||||
565490BE1D5AE236005622CB /* DatabaseValue.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238751B9C75030082EB20 /* DatabaseValue.swift */; };
|
||||
565490BF1D5AE236005622CB /* DatabaseValueConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560D923E1C672C3E00F4F92B /* DatabaseValueConvertible.swift */; };
|
||||
565490C01D5AE236005622CB /* DatabaseWriter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563363C31C942C37000BE133 /* DatabaseWriter.swift */; };
|
||||
565490C11D5AE236005622CB /* Request.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5636E9BB1D22574100B9B05F /* Request.swift */; };
|
||||
565490C11D5AE236005622CB /* FetchRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5636E9BB1D22574100B9B05F /* FetchRequest.swift */; };
|
||||
565490C21D5AE236005622CB /* Row.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238761B9C75030082EB20 /* Row.swift */; };
|
||||
565490C31D5AE236005622CB /* RowAdapter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 567404871CEF84C8003ED5CC /* RowAdapter.swift */; };
|
||||
565490C41D5AE236005622CB /* SchedulingWatchdog.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56BB6EA81D3009B100A1CA52 /* SchedulingWatchdog.swift */; };
|
||||
@@ -182,7 +182,7 @@
|
||||
565490D91D5AE252005622CB /* Migration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B7F4391BEB42D500E39BBF /* Migration.swift */; };
|
||||
565490DA1D5AE252005622CB /* QueryInterfaceRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56300B6F1C53F592005A543B /* QueryInterfaceRequest.swift */; };
|
||||
565490DB1D5AE252005622CB /* SQLCollatedExpression.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5605F1891C6B1A8700235C62 /* SQLCollatedExpression.swift */; };
|
||||
565490DE1D5AE252005622CB /* QueryInterfaceSelectQueryDefinition.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5605F18C1C6B1A8700235C62 /* QueryInterfaceSelectQueryDefinition.swift */; };
|
||||
565490DE1D5AE252005622CB /* QueryInterfaceQuery.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5605F18C1C6B1A8700235C62 /* QueryInterfaceQuery.swift */; };
|
||||
565490DF1D5AE252005622CB /* TableDefinition.swift in Sources */ = {isa = PBXBuildFile; fileRef = 566AD8B11D5318F4002EC1A8 /* TableDefinition.swift */; };
|
||||
565490E01D5AE252005622CB /* FetchedRecordsController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 31A7787C1C6A4DD600F507F6 /* FetchedRecordsController.swift */; };
|
||||
565490E11D5AE252005622CB /* Persistable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560D92441C672C4B00F4F92B /* Persistable.swift */; };
|
||||
@@ -267,8 +267,8 @@
|
||||
5672DE6A1CDB751D0022BA81 /* DatabasePoolBackupTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5672DE661CDB751D0022BA81 /* DatabasePoolBackupTests.swift */; };
|
||||
567404881CEF84C8003ED5CC /* RowAdapter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 567404871CEF84C8003ED5CC /* RowAdapter.swift */; };
|
||||
5674048A1CEF84C8003ED5CC /* RowAdapter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 567404871CEF84C8003ED5CC /* RowAdapter.swift */; };
|
||||
56741EA81E66A8B3003E422D /* RequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56741EA71E66A8B3003E422D /* RequestTests.swift */; };
|
||||
56741EAC1E66A8B3003E422D /* RequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56741EA71E66A8B3003E422D /* RequestTests.swift */; };
|
||||
56741EA81E66A8B3003E422D /* FetchRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56741EA71E66A8B3003E422D /* FetchRequestTests.swift */; };
|
||||
56741EAC1E66A8B3003E422D /* FetchRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56741EA71E66A8B3003E422D /* FetchRequestTests.swift */; };
|
||||
5674A6E41F307F0E0095F066 /* DatabaseValueConvertible+Decodable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5674A6E31F307F0E0095F066 /* DatabaseValueConvertible+Decodable.swift */; };
|
||||
5674A6E81F307F0E0095F066 /* DatabaseValueConvertible+Decodable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5674A6E31F307F0E0095F066 /* DatabaseValueConvertible+Decodable.swift */; };
|
||||
5674A6E91F307F0E0095F066 /* DatabaseValueConvertible+Decodable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5674A6E31F307F0E0095F066 /* DatabaseValueConvertible+Decodable.swift */; };
|
||||
@@ -364,6 +364,9 @@
|
||||
5698AD351DABAF4A0056AF8C /* FTS5CustomTokenizer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698AD341DABAF4A0056AF8C /* FTS5CustomTokenizer.swift */; };
|
||||
5698AD381DABAF4A0056AF8C /* FTS5CustomTokenizer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698AD341DABAF4A0056AF8C /* FTS5CustomTokenizer.swift */; };
|
||||
5698AD3B1DABAF4A0056AF8C /* FTS5CustomTokenizer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698AD341DABAF4A0056AF8C /* FTS5CustomTokenizer.swift */; };
|
||||
569A98ED2039B6F3008D7DBF /* Fixits-3.0.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569A98EC2039B6F3008D7DBF /* Fixits-3.0.swift */; };
|
||||
569A98EE2039B6F3008D7DBF /* Fixits-3.0.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569A98EC2039B6F3008D7DBF /* Fixits-3.0.swift */; };
|
||||
569A98EF2039B6F3008D7DBF /* Fixits-3.0.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569A98EC2039B6F3008D7DBF /* Fixits-3.0.swift */; };
|
||||
569C1EB51CF07DDD0042627B /* SchedulingWatchdogTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569C1EB11CF07DDD0042627B /* SchedulingWatchdogTests.swift */; };
|
||||
569EF0E2200D2D8400A9FA45 /* DatabaseRegion.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569EF0E1200D2D8400A9FA45 /* DatabaseRegion.swift */; };
|
||||
569EF0E3200D2D8400A9FA45 /* DatabaseRegion.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569EF0E1200D2D8400A9FA45 /* DatabaseRegion.swift */; };
|
||||
@@ -756,7 +759,7 @@
|
||||
5605F1581C672E4000235C62 /* StandardLibrary.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StandardLibrary.swift; sourceTree = "<group>"; };
|
||||
5605F1861C69111300235C62 /* DatabaseRegionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseRegionTests.swift; sourceTree = "<group>"; };
|
||||
5605F1891C6B1A8700235C62 /* SQLCollatedExpression.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SQLCollatedExpression.swift; sourceTree = "<group>"; };
|
||||
5605F18C1C6B1A8700235C62 /* QueryInterfaceSelectQueryDefinition.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QueryInterfaceSelectQueryDefinition.swift; sourceTree = "<group>"; };
|
||||
5605F18C1C6B1A8700235C62 /* QueryInterfaceQuery.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QueryInterfaceQuery.swift; sourceTree = "<group>"; };
|
||||
5607EFD21BB8254800605DE3 /* TransactionObserverTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TransactionObserverTests.swift; sourceTree = "<group>"; };
|
||||
560A37A31C8F625000949E71 /* DatabasePool.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabasePool.swift; sourceTree = "<group>"; };
|
||||
560A37A61C8FF6E500949E71 /* SerializedDatabase.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SerializedDatabase.swift; sourceTree = "<group>"; };
|
||||
@@ -797,7 +800,7 @@
|
||||
563363D41C94484E000BE133 /* DatabaseQueueReleaseMemoryTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseQueueReleaseMemoryTests.swift; sourceTree = "<group>"; };
|
||||
563363F81C960711000BE133 /* PerformanceRealmTests.realm */ = {isa = PBXFileReference; lastKnownFileType = file; path = PerformanceRealmTests.realm; sourceTree = "<group>"; };
|
||||
5634B1061CF9B970005360B9 /* TransactionObserverSavepointsTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TransactionObserverSavepointsTests.swift; sourceTree = "<group>"; };
|
||||
5636E9BB1D22574100B9B05F /* Request.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Request.swift; sourceTree = "<group>"; };
|
||||
5636E9BB1D22574100B9B05F /* FetchRequest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FetchRequest.swift; sourceTree = "<group>"; };
|
||||
56439B501F4CA1DC0066043F /* GRDBOSXPerformanceComparisonTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = GRDBOSXPerformanceComparisonTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
564448821EF56B1B00DD2861 /* DatabaseAfterNextTransactionCommitTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseAfterNextTransactionCommitTests.swift; sourceTree = "<group>"; };
|
||||
564A50C61BFF4B7F00B3A3A2 /* DatabaseCollationTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseCollationTests.swift; sourceTree = "<group>"; };
|
||||
@@ -846,7 +849,7 @@
|
||||
5672DE581CDB72520022BA81 /* DatabaseQueueBackupTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseQueueBackupTests.swift; sourceTree = "<group>"; };
|
||||
5672DE661CDB751D0022BA81 /* DatabasePoolBackupTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabasePoolBackupTests.swift; sourceTree = "<group>"; };
|
||||
567404871CEF84C8003ED5CC /* RowAdapter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RowAdapter.swift; sourceTree = "<group>"; };
|
||||
56741EA71E66A8B3003E422D /* RequestTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RequestTests.swift; sourceTree = "<group>"; };
|
||||
56741EA71E66A8B3003E422D /* FetchRequestTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FetchRequestTests.swift; sourceTree = "<group>"; };
|
||||
5674A6E21F307F0E0095F066 /* DatabaseValueConvertible+Encodable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DatabaseValueConvertible+Encodable.swift"; sourceTree = "<group>"; };
|
||||
5674A6E31F307F0E0095F066 /* DatabaseValueConvertible+Decodable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DatabaseValueConvertible+Decodable.swift"; sourceTree = "<group>"; };
|
||||
5674A6F21F307F600095F066 /* RowConvertible+Decodable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "RowConvertible+Decodable.swift"; sourceTree = "<group>"; };
|
||||
@@ -898,6 +901,7 @@
|
||||
5698AD151DAAD16F0056AF8C /* FTS5Tokenizer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS5Tokenizer.swift; sourceTree = "<group>"; };
|
||||
5698AD201DABAEFA0056AF8C /* FTS5WrapperTokenizer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS5WrapperTokenizer.swift; sourceTree = "<group>"; };
|
||||
5698AD341DABAF4A0056AF8C /* FTS5CustomTokenizer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS5CustomTokenizer.swift; sourceTree = "<group>"; };
|
||||
569A98EC2039B6F3008D7DBF /* Fixits-3.0.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Fixits-3.0.swift"; sourceTree = "<group>"; };
|
||||
569C1EB11CF07DDD0042627B /* SchedulingWatchdogTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SchedulingWatchdogTests.swift; sourceTree = "<group>"; };
|
||||
569EF0E1200D2D8400A9FA45 /* DatabaseRegion.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DatabaseRegion.swift; sourceTree = "<group>"; };
|
||||
56A238131B9C74A90082EB20 /* DatabaseTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseTests.swift; sourceTree = "<group>"; };
|
||||
@@ -1278,8 +1282,8 @@
|
||||
56CEB5401EAA359A00BFAF62 /* Column.swift */,
|
||||
56CEB5101EAA324B00BFAF62 /* FTS3+QueryInterfaceRequest.swift */,
|
||||
56CEB5181EAA328900BFAF62 /* FTS5+QueryInterface.swift */,
|
||||
5605F18C1C6B1A8700235C62 /* QueryInterfaceQuery.swift */,
|
||||
56300B6F1C53F592005A543B /* QueryInterfaceRequest.swift */,
|
||||
5605F18C1C6B1A8700235C62 /* QueryInterfaceSelectQueryDefinition.swift */,
|
||||
5605F1891C6B1A8700235C62 /* SQLCollatedExpression.swift */,
|
||||
566475991D97D8A000FF74B8 /* SQLCollection.swift */,
|
||||
56CEB5411EAA359A00BFAF62 /* SQLExpressible.swift */,
|
||||
@@ -1426,11 +1430,11 @@
|
||||
56A238191B9C74A90082EB20 /* DatabaseValueConvertible */,
|
||||
56A238181B9C74A90082EB20 /* DatabaseValueTests.swift */,
|
||||
562756421E963AAC0035B653 /* DatabaseWriterTests.swift */,
|
||||
56741EA71E66A8B3003E422D /* FetchRequestTests.swift */,
|
||||
56A5EF0E1EF7F20B00F03071 /* ForeignKeyInfoTests.swift */,
|
||||
567A80521D41350C00C7DCEC /* IndexInfoTests.swift */,
|
||||
565EFAED1D0436CE00A8FA9D /* NumericOverflowTests.swift */,
|
||||
56D5075D1F6BAE8600AE1C5B /* PrimaryKeyInfoTests.swift */,
|
||||
56741EA71E66A8B3003E422D /* RequestTests.swift */,
|
||||
56F3E7481E66F83A00BF0F01 /* ResultCodeTests.swift */,
|
||||
56A2381D1B9C74A90082EB20 /* Row */,
|
||||
569C1EB11CF07DDD0042627B /* SchedulingWatchdogTests.swift */,
|
||||
@@ -1521,7 +1525,7 @@
|
||||
56A238751B9C75030082EB20 /* DatabaseValue.swift */,
|
||||
560D923E1C672C3E00F4F92B /* DatabaseValueConvertible.swift */,
|
||||
563363C31C942C37000BE133 /* DatabaseWriter.swift */,
|
||||
5636E9BB1D22574100B9B05F /* Request.swift */,
|
||||
5636E9BB1D22574100B9B05F /* FetchRequest.swift */,
|
||||
56A238761B9C75030082EB20 /* Row.swift */,
|
||||
567404871CEF84C8003ED5CC /* RowAdapter.swift */,
|
||||
56BB6EA81D3009B100A1CA52 /* SchedulingWatchdog.swift */,
|
||||
@@ -1616,6 +1620,7 @@
|
||||
56E06F051E859064008AE2A4 /* Fixits-0.102.0.swift */,
|
||||
56D121591ED34978001347D2 /* Fixits-0.109.0.swift */,
|
||||
56873BEB1F2CB400004D24B4 /* Fixits-1.2.swift */,
|
||||
569A98EC2039B6F3008D7DBF /* Fixits-3.0.swift */,
|
||||
56B1C3CC201C8D0E001938DA /* Swift4.1.swift */,
|
||||
);
|
||||
path = Legacy;
|
||||
@@ -2167,6 +2172,7 @@
|
||||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
569A98EF2039B6F3008D7DBF /* Fixits-3.0.swift in Sources */,
|
||||
56B964BF1DA51D0A0002DA19 /* FTS5Pattern.swift in Sources */,
|
||||
56D51D061EA789FA0074638A /* RowConvertible+TableMapping.swift in Sources */,
|
||||
565490CE1D5AE252005622CB /* NSNull.swift in Sources */,
|
||||
@@ -2175,7 +2181,7 @@
|
||||
566475C01D981AD200FF74B8 /* SQLSpecificExpressible+QueryInterface.swift in Sources */,
|
||||
56CEB51F1EAA328900BFAF62 /* FTS5+QueryInterface.swift in Sources */,
|
||||
565490E21D5AE252005622CB /* Record.swift in Sources */,
|
||||
565490C11D5AE236005622CB /* Request.swift in Sources */,
|
||||
565490C11D5AE236005622CB /* FetchRequest.swift in Sources */,
|
||||
5698AD1C1DAAD17F0056AF8C /* FTS5Tokenizer.swift in Sources */,
|
||||
56CEB5171EAA324B00BFAF62 /* FTS3+QueryInterfaceRequest.swift in Sources */,
|
||||
56B964B71DA51D010002DA19 /* FTS5TokenizerDescriptor.swift in Sources */,
|
||||
@@ -2251,7 +2257,7 @@
|
||||
565490D31D5AE252005622CB /* (null) in Sources */,
|
||||
566475D91D981D5E00FF74B8 /* SQLOperators.swift in Sources */,
|
||||
566B910F1FA4C3970012D5B0 /* Database+Statements.swift in Sources */,
|
||||
565490DE1D5AE252005622CB /* QueryInterfaceSelectQueryDefinition.swift in Sources */,
|
||||
565490DE1D5AE252005622CB /* QueryInterfaceQuery.swift in Sources */,
|
||||
56F5ABDD1D814330001F60CB /* UUID.swift in Sources */,
|
||||
565490CB1D5AE252005622CB /* (null) in Sources */,
|
||||
565490D61D5AE252005622CB /* StandardLibrary.swift in Sources */,
|
||||
@@ -2287,7 +2293,7 @@
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
56BF6D401DEF47DA006039A3 /* Fixits-Swift2.swift in Sources */,
|
||||
5636E9BF1D22574100B9B05F /* Request.swift in Sources */,
|
||||
5636E9BF1D22574100B9B05F /* FetchRequest.swift in Sources */,
|
||||
56BB6EAC1D3009B100A1CA52 /* SchedulingWatchdog.swift in Sources */,
|
||||
56300B791C53F592005A543B /* QueryInterfaceRequest.swift in Sources */,
|
||||
56CEB5561EAA359A00BFAF62 /* SQLExpression.swift in Sources */,
|
||||
@@ -2305,6 +2311,7 @@
|
||||
56CEB5141EAA324B00BFAF62 /* FTS3+QueryInterfaceRequest.swift in Sources */,
|
||||
566475CF1D981D5E00FF74B8 /* SQLFunctions.swift in Sources */,
|
||||
5659F49B1EA8D989004A4992 /* Pool.swift in Sources */,
|
||||
569A98EE2039B6F3008D7DBF /* Fixits-3.0.swift in Sources */,
|
||||
56CEB51C1EAA328900BFAF62 /* FTS5+QueryInterface.swift in Sources */,
|
||||
5698AC3A1D9E5A590056AF8C /* FTS3Pattern.swift in Sources */,
|
||||
5664759D1D97D8A000FF74B8 /* SQLCollection.swift in Sources */,
|
||||
@@ -2337,7 +2344,7 @@
|
||||
56A2388C1B9C75030082EB20 /* Statement.swift in Sources */,
|
||||
5659F4931EA8D964004A4992 /* ReadWriteBox.swift in Sources */,
|
||||
56B1C3CE201C8D0E001938DA /* Swift4.1.swift in Sources */,
|
||||
5605F1941C6B1A8700235C62 /* QueryInterfaceSelectQueryDefinition.swift in Sources */,
|
||||
5605F1941C6B1A8700235C62 /* QueryInterfaceQuery.swift in Sources */,
|
||||
56B7F43B1BEB42D500E39BBF /* Migration.swift in Sources */,
|
||||
5690C3431D23E82A00E59934 /* Data.swift in Sources */,
|
||||
5674A7001F307F600095F066 /* RowConvertible+Decodable.swift in Sources */,
|
||||
@@ -2445,7 +2452,7 @@
|
||||
56F3E74D1E66F83A00BF0F01 /* ResultCodeTests.swift in Sources */,
|
||||
56EB0AB31BCD787300A3DC55 /* DataMemoryTests.swift in Sources */,
|
||||
56176C7F1EACCD2F000F3F2B /* EncryptionTests.swift in Sources */,
|
||||
56741EAC1E66A8B3003E422D /* RequestTests.swift in Sources */,
|
||||
56741EAC1E66A8B3003E422D /* FetchRequestTests.swift in Sources */,
|
||||
5672DE5C1CDB72520022BA81 /* DatabaseQueueBackupTests.swift in Sources */,
|
||||
56A2385E1B9C74A90082EB20 /* RecordCopyTests.swift in Sources */,
|
||||
56176C6C1EACCCC9000F3F2B /* FTS5PatternTests.swift in Sources */,
|
||||
@@ -2593,7 +2600,7 @@
|
||||
56F3E7491E66F83A00BF0F01 /* ResultCodeTests.swift in Sources */,
|
||||
5698ACD71DA925420056AF8C /* RowTestCase.swift in Sources */,
|
||||
56176C7D1EACCD2D000F3F2B /* EncryptionTests.swift in Sources */,
|
||||
56741EA81E66A8B3003E422D /* RequestTests.swift in Sources */,
|
||||
56741EA81E66A8B3003E422D /* FetchRequestTests.swift in Sources */,
|
||||
56D496831D813147008276D7 /* DatabaseSavepointTests.swift in Sources */,
|
||||
56D496871D81316E008276D7 /* DatabaseTimestampTests.swift in Sources */,
|
||||
56176C5A1EACCCC7000F3F2B /* FTS5PatternTests.swift in Sources */,
|
||||
@@ -2682,7 +2689,7 @@
|
||||
files = (
|
||||
56873BEC1F2CB400004D24B4 /* Fixits-1.2.swift in Sources */,
|
||||
56BF6D3D1DEF47DA006039A3 /* Fixits-Swift2.swift in Sources */,
|
||||
5636E9BC1D22574100B9B05F /* Request.swift in Sources */,
|
||||
5636E9BC1D22574100B9B05F /* FetchRequest.swift in Sources */,
|
||||
56BB6EA91D3009B100A1CA52 /* SchedulingWatchdog.swift in Sources */,
|
||||
566B91091FA4C3970012D5B0 /* Database+Statements.swift in Sources */,
|
||||
566B91231FA4CF810012D5B0 /* Database+Schema.swift in Sources */,
|
||||
@@ -2739,7 +2746,7 @@
|
||||
5674A6EB1F307F0E0095F066 /* DatabaseValueConvertible+Encodable.swift in Sources */,
|
||||
560A37A41C8F625000949E71 /* DatabasePool.swift in Sources */,
|
||||
56B7F43A1BEB42D500E39BBF /* Migration.swift in Sources */,
|
||||
5605F1931C6B1A8700235C62 /* QueryInterfaceSelectQueryDefinition.swift in Sources */,
|
||||
5605F1931C6B1A8700235C62 /* QueryInterfaceQuery.swift in Sources */,
|
||||
566B912B1FA4D0CC0012D5B0 /* StatementAuthorizer.swift in Sources */,
|
||||
56A2388B1B9C75030082EB20 /* Statement.swift in Sources */,
|
||||
56B1C3CD201C8D0E001938DA /* Swift4.1.swift in Sources */,
|
||||
@@ -2761,6 +2768,7 @@
|
||||
566AD8B21D5318F4002EC1A8 /* TableDefinition.swift in Sources */,
|
||||
5698AD211DABAEFA0056AF8C /* FTS5WrapperTokenizer.swift in Sources */,
|
||||
56A238831B9C75030082EB20 /* DatabaseQueue.swift in Sources */,
|
||||
569A98ED2039B6F3008D7DBF /* Fixits-3.0.swift in Sources */,
|
||||
5605F1671C672E4000235C62 /* NSNumber.swift in Sources */,
|
||||
56A238871B9C75030082EB20 /* Row.swift in Sources */,
|
||||
5605F1731C672E4000235C62 /* StandardLibrary.swift in Sources */,
|
||||
|
||||
@@ -194,64 +194,6 @@ extension DatabaseValueConvertible {
|
||||
}
|
||||
}
|
||||
|
||||
extension DatabaseValueConvertible {
|
||||
|
||||
// MARK: Fetching From Request
|
||||
|
||||
/// Returns a cursor over values fetched from a fetch request.
|
||||
///
|
||||
/// let nameColumn = Column("name")
|
||||
/// let request = Player.select(nameColumn)
|
||||
/// let names = try String.fetchCursor(db, request) // Cursor of String
|
||||
/// for let name = try names.next() { // String
|
||||
/// ...
|
||||
/// }
|
||||
///
|
||||
/// If the database is modified during the cursor iteration, the remaining
|
||||
/// elements are undefined.
|
||||
///
|
||||
/// The cursor must be iterated in a protected dispath queue.
|
||||
///
|
||||
/// - parameters:
|
||||
/// - db: A database connection.
|
||||
/// - request: A fetch request.
|
||||
/// - returns: A cursor over fetched values.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public static func fetchCursor(_ db: Database, _ request: Request) throws -> DatabaseValueCursor<Self> {
|
||||
let (statement, adapter) = try request.prepare(db)
|
||||
return try fetchCursor(statement, adapter: adapter)
|
||||
}
|
||||
|
||||
/// Returns an array of values fetched from a fetch request.
|
||||
///
|
||||
/// let nameColumn = Column("name")
|
||||
/// let request = Player.select(nameColumn)
|
||||
/// let names = try String.fetchAll(db, request) // [String]
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public static func fetchAll(_ db: Database, _ request: Request) throws -> [Self] {
|
||||
let (statement, adapter) = try request.prepare(db)
|
||||
return try fetchAll(statement, adapter: adapter)
|
||||
}
|
||||
|
||||
/// Returns a single value fetched from a fetch request.
|
||||
///
|
||||
/// The result is nil if the query returns no row, or if no value can be
|
||||
/// extracted from the first row.
|
||||
///
|
||||
/// let nameColumn = Column("name")
|
||||
/// let request = Player.select(nameColumn)
|
||||
/// let name = try String.fetchOne(db, request) // String?
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public static func fetchOne(_ db: Database, _ request: Request) throws -> Self? {
|
||||
let (statement, adapter) = try request.prepare(db)
|
||||
return try fetchOne(statement, adapter: adapter)
|
||||
}
|
||||
}
|
||||
|
||||
extension DatabaseValueConvertible {
|
||||
|
||||
// MARK: Fetching From SQL
|
||||
@@ -276,7 +218,7 @@ extension DatabaseValueConvertible {
|
||||
/// - returns: A cursor over fetched values.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public static func fetchCursor(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> DatabaseValueCursor<Self> {
|
||||
return try fetchCursor(db, SQLRequest(sql, arguments: arguments, adapter: adapter))
|
||||
return try SQLRequest<Self>(sql, arguments: arguments, adapter: adapter).fetchCursor(db)
|
||||
}
|
||||
|
||||
/// Returns an array of values fetched from an SQL query.
|
||||
@@ -291,7 +233,7 @@ extension DatabaseValueConvertible {
|
||||
/// - returns: An array.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public static func fetchAll(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> [Self] {
|
||||
return try fetchAll(db, SQLRequest(sql, arguments: arguments, adapter: adapter))
|
||||
return try SQLRequest<Self>(sql, arguments: arguments, adapter: adapter).fetchAll(db)
|
||||
}
|
||||
|
||||
/// Returns a single value fetched from an SQL query.
|
||||
@@ -309,10 +251,64 @@ extension DatabaseValueConvertible {
|
||||
/// - returns: An optional value.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public static func fetchOne(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> Self? {
|
||||
return try fetchOne(db, SQLRequest(sql, arguments: arguments, adapter: adapter))
|
||||
return try SQLRequest<Self>(sql, arguments: arguments, adapter: adapter).fetchOne(db)
|
||||
}
|
||||
}
|
||||
|
||||
extension FetchRequest where RowDecoder: DatabaseValueConvertible {
|
||||
|
||||
// MARK: Fetching Values
|
||||
|
||||
/// A cursor over fetched values.
|
||||
///
|
||||
/// let request: ... // Some TypedRequest that fetches String
|
||||
/// let strings = try request.fetchCursor(db) // Cursor of String
|
||||
/// while let string = try strings.next() { // String
|
||||
/// ...
|
||||
/// }
|
||||
///
|
||||
/// If the database is modified during the cursor iteration, the remaining
|
||||
/// elements are undefined.
|
||||
///
|
||||
/// The cursor must be iterated in a protected dispath queue.
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
/// - returns: A cursor over fetched values.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public func fetchCursor(_ db: Database) throws -> DatabaseValueCursor<RowDecoder> {
|
||||
let (statement, adapter) = try prepare(db)
|
||||
return try RowDecoder.fetchCursor(statement, adapter: adapter)
|
||||
}
|
||||
|
||||
/// An array of fetched values.
|
||||
///
|
||||
/// let request: ... // Some TypedRequest that fetches String
|
||||
/// let strings = try request.fetchAll(db) // [String]
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
/// - returns: An array of values.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public func fetchAll(_ db: Database) throws -> [RowDecoder] {
|
||||
let (statement, adapter) = try prepare(db)
|
||||
return try RowDecoder.fetchAll(statement, adapter: adapter)
|
||||
}
|
||||
|
||||
/// The first fetched value.
|
||||
///
|
||||
/// The result is nil if the request returns no row, or if no value can be
|
||||
/// extracted from the first row.
|
||||
///
|
||||
/// let request: ... // Some TypedRequest that fetches String
|
||||
/// let string = try request.fetchOne(db) // String?
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
/// - returns: An optional value.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public func fetchOne(_ db: Database) throws -> RowDecoder? {
|
||||
let (statement, adapter) = try prepare(db)
|
||||
return try RowDecoder.fetchOne(statement, adapter: adapter)
|
||||
}
|
||||
}
|
||||
|
||||
/// Swift's Optional comes with built-in methods that allow to fetch cursors
|
||||
/// and arrays of optional DatabaseValueConvertible:
|
||||
@@ -368,48 +364,6 @@ extension Optional where Wrapped: DatabaseValueConvertible {
|
||||
}
|
||||
}
|
||||
|
||||
extension Optional where Wrapped: DatabaseValueConvertible {
|
||||
|
||||
// MARK: Fetching From Request
|
||||
|
||||
/// Returns a cursor over optional values fetched from a fetch request.
|
||||
///
|
||||
/// let nameColumn = Column("name")
|
||||
/// let request = Player.select(nameColumn)
|
||||
/// let names = try Optional<String>.fetchCursor(db, request) // Cursor of String?
|
||||
/// while let name = try names.next() { // String?
|
||||
/// ...
|
||||
/// }
|
||||
///
|
||||
/// If the database is modified during the cursor iteration, the remaining
|
||||
/// elements are undefined.
|
||||
///
|
||||
/// The cursor must be iterated in a protected dispath queue.
|
||||
///
|
||||
/// - parameters:
|
||||
/// - db: A database connection.
|
||||
/// - requet: A fetch request.
|
||||
/// - returns: A cursor over fetched optional values.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public static func fetchCursor(_ db: Database, _ request: Request) throws -> NullableDatabaseValueCursor<Wrapped> {
|
||||
let (statement, adapter) = try request.prepare(db)
|
||||
return try fetchCursor(statement, adapter: adapter)
|
||||
}
|
||||
|
||||
/// Returns an array of optional values fetched from a fetch request.
|
||||
///
|
||||
/// let nameColumn = Column("name")
|
||||
/// let request = Player.select(nameColumn)
|
||||
/// let names = try Optional<String>.fetchAll(db, request) // [String?]
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public static func fetchAll(_ db: Database, _ request: Request) throws -> [Wrapped?] {
|
||||
let (statement, adapter) = try request.prepare(db)
|
||||
return try fetchAll(statement, adapter: adapter)
|
||||
}
|
||||
}
|
||||
|
||||
extension Optional where Wrapped: DatabaseValueConvertible {
|
||||
|
||||
// MARK: Fetching From SQL
|
||||
@@ -434,7 +388,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(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> NullableDatabaseValueCursor<Wrapped> {
|
||||
return try fetchCursor(db, SQLRequest(sql, arguments: arguments, adapter: adapter))
|
||||
return try SQLRequest<Wrapped?>(sql, arguments: arguments, adapter: adapter).fetchCursor(db)
|
||||
}
|
||||
|
||||
/// Returns an array of optional values fetched from an SQL query.
|
||||
@@ -449,6 +403,45 @@ 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(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> [Wrapped?] {
|
||||
return try fetchAll(db, SQLRequest(sql, arguments: arguments, adapter: adapter))
|
||||
return try SQLRequest<Wrapped?>(sql, arguments: arguments, adapter: adapter).fetchAll(db)
|
||||
}
|
||||
}
|
||||
|
||||
extension FetchRequest where RowDecoder: _OptionalProtocol, RowDecoder._Wrapped: DatabaseValueConvertible {
|
||||
|
||||
// MARK: Fetching Optional values
|
||||
|
||||
/// A cursor over fetched optional values.
|
||||
///
|
||||
/// let request: ... // Some TypedRequest that fetches Optional<String>
|
||||
/// let strings = try request.fetchCursor(db) // Cursor of String?
|
||||
/// while let string = try strings.next() { // String?
|
||||
/// ...
|
||||
/// }
|
||||
///
|
||||
/// If the database is modified during the cursor iteration, the remaining
|
||||
/// elements are undefined.
|
||||
///
|
||||
/// The cursor must be iterated in a protected dispath queue.
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
/// - returns: A cursor over fetched values.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public func fetchCursor(_ db: Database) throws -> NullableDatabaseValueCursor<RowDecoder._Wrapped> {
|
||||
let (statement, adapter) = try prepare(db)
|
||||
return try Optional<RowDecoder._Wrapped>.fetchCursor(statement, adapter: adapter)
|
||||
}
|
||||
|
||||
/// An array of fetched optional values.
|
||||
///
|
||||
/// let request: ... // Some TypedRequest that fetches Optional<String>
|
||||
/// let strings = try request.fetchAll(db) // [String?]
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
/// - returns: An array of values.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public func fetchAll(_ db: Database) throws -> [RowDecoder._Wrapped?] {
|
||||
let (statement, adapter) = try prepare(db)
|
||||
return try Optional<RowDecoder._Wrapped>.fetchAll(statement, adapter: adapter)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,260 @@
|
||||
/// The protocol for all types that define a way to fetch database content.
|
||||
///
|
||||
/// struct Player: RowConvertible { ... }
|
||||
/// let request: ... // Some FetchRequest that fetches Player
|
||||
/// try request.fetchCursor(db) // Cursor of Player
|
||||
/// try request.fetchAll(db) // [Player]
|
||||
/// try request.fetchOne(db) // Player?
|
||||
public protocol FetchRequest {
|
||||
/// The type that can convert raw database rows to fetched values
|
||||
associatedtype RowDecoder
|
||||
|
||||
/// A tuple that contains a prepared statement that is ready to be
|
||||
/// executed, and an eventual row adapter.
|
||||
func prepare(_ db: Database) throws -> (SelectStatement, RowAdapter?)
|
||||
|
||||
/// The number of rows fetched by the request.
|
||||
///
|
||||
/// Default implementation builds a naive SQL query based on the statement
|
||||
/// returned by the `prepare` method: `SELECT COUNT(*) FROM (...)`.
|
||||
///
|
||||
/// Adopting types can refine this countRequest method and return more
|
||||
/// efficient SQL.
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
func fetchCount(_ db: Database) throws -> Int
|
||||
|
||||
/// The database region that the request looks into.
|
||||
///
|
||||
/// This method has a default implementation.
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
func fetchedRegion(_ db: Database) throws -> DatabaseRegion
|
||||
}
|
||||
|
||||
extension FetchRequest {
|
||||
/// The number of rows fetched by the request.
|
||||
///
|
||||
/// This default implementation builds a naive SQL query based on the
|
||||
/// statement returned by the `prepare` method: `SELECT COUNT(*) FROM (...)`.
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
public func fetchCount(_ db: Database) throws -> Int {
|
||||
let (statement, _) = try prepare(db)
|
||||
let sql = "SELECT COUNT(*) FROM (\(statement.sql))"
|
||||
return try Int.fetchOne(db, sql, arguments: statement.arguments)!
|
||||
}
|
||||
|
||||
/// The database region that the request looks into.
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
public func fetchedRegion(_ db: Database) throws -> DatabaseRegion {
|
||||
let (statement, _) = try prepare(db)
|
||||
return statement.fetchedRegion
|
||||
}
|
||||
}
|
||||
|
||||
extension FetchRequest {
|
||||
/// Returns a request bound to type T.
|
||||
///
|
||||
/// The returned request can fetch if the type T is fetchable (Row,
|
||||
/// value, record).
|
||||
///
|
||||
/// // Int?
|
||||
/// let maxScore = Player
|
||||
/// .select(max(scoreColumn))
|
||||
/// .asRequest(of: Int.self) // <--
|
||||
/// .fetchOne(db)
|
||||
///
|
||||
/// - parameter type: The fetched type T
|
||||
/// - returns: A typed request bound to type T.
|
||||
public func asRequest<T>(of type: T.Type) -> AnyFetchRequest<T> {
|
||||
return AnyFetchRequest(self)
|
||||
}
|
||||
|
||||
/// Returns an adapted request.
|
||||
public func adapted(_ adapter: @escaping (Database) throws -> RowAdapter) -> AdaptedFetchRequest<Self> {
|
||||
return AdaptedFetchRequest(self, adapter)
|
||||
}
|
||||
}
|
||||
|
||||
/// An adapted request.
|
||||
public struct AdaptedFetchRequest<Base: FetchRequest> : FetchRequest {
|
||||
public typealias RowDecoder = Base.RowDecoder
|
||||
|
||||
private let base: Base
|
||||
private let adapter: (Database) throws -> RowAdapter
|
||||
|
||||
/// Creates an adapted request from a base request and a closure that builds
|
||||
/// a row adapter from a database connection.
|
||||
init(_ base: Base, _ adapter: @escaping (Database) throws -> RowAdapter) {
|
||||
self.base = base
|
||||
self.adapter = adapter
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
public func prepare(_ db: Database) throws -> (SelectStatement, RowAdapter?) {
|
||||
let (statement, baseAdapter) = try base.prepare(db)
|
||||
if let baseAdapter = baseAdapter {
|
||||
return try (statement, ChainedAdapter(first: baseAdapter, second: adapter(db)))
|
||||
} else {
|
||||
return try (statement, adapter(db))
|
||||
}
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
public func fetchCount(_ db: Database) throws -> Int {
|
||||
return try base.fetchCount(db)
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
public func fetchedRegion(_ db: Database) throws -> DatabaseRegion {
|
||||
return try base.fetchedRegion(db)
|
||||
}
|
||||
}
|
||||
|
||||
/// A type-erased FetchRequest.
|
||||
///
|
||||
/// An AnyFetchRequest forwards its operations to an underlying request,
|
||||
/// hiding its specifics.
|
||||
public struct AnyFetchRequest<T> : FetchRequest {
|
||||
public typealias RowDecoder = T
|
||||
|
||||
private let _prepare: (Database) throws -> (SelectStatement, RowAdapter?)
|
||||
private let _fetchCount: (Database) throws -> Int
|
||||
private let _fetchedRegion: (Database) throws -> DatabaseRegion
|
||||
|
||||
/// Creates a new request that wraps and forwards operations to `request`.
|
||||
public init<Request: FetchRequest>(_ request: Request) {
|
||||
_prepare = request.prepare
|
||||
_fetchCount = request.fetchCount
|
||||
_fetchedRegion = request.fetchedRegion
|
||||
}
|
||||
|
||||
/// Creates a new request whose `prepare()` method wraps and forwards
|
||||
/// operations the argument closure.
|
||||
public init(_ prepare: @escaping (Database) throws -> (SelectStatement, RowAdapter?)) {
|
||||
_prepare = { db in
|
||||
try prepare(db)
|
||||
}
|
||||
|
||||
_fetchCount = { db in
|
||||
let (statement, _) = try prepare(db)
|
||||
let sql = "SELECT COUNT(*) FROM (\(statement.sql))"
|
||||
return try Int.fetchOne(db, sql, arguments: statement.arguments)!
|
||||
}
|
||||
|
||||
_fetchedRegion = { db in
|
||||
let (statement, _) = try prepare(db)
|
||||
return statement.fetchedRegion
|
||||
}
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
public func prepare(_ db: Database) throws -> (SelectStatement, RowAdapter?) {
|
||||
return try _prepare(db)
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
public func fetchCount(_ db: Database) throws -> Int {
|
||||
return try _fetchCount(db)
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
public func fetchedRegion(_ db: Database) throws -> DatabaseRegion {
|
||||
return try _fetchedRegion(db)
|
||||
}
|
||||
}
|
||||
|
||||
/// A Request built from raw SQL.
|
||||
public struct SQLRequest<T> : FetchRequest {
|
||||
public typealias RowDecoder = T
|
||||
|
||||
public let sql: String
|
||||
public let arguments: StatementArguments?
|
||||
public let adapter: RowAdapter?
|
||||
private let cache: Cache?
|
||||
|
||||
/// Creates a new request from an SQL string, optional arguments, and
|
||||
/// optional row adapter.
|
||||
///
|
||||
/// let request = SQLRequest("SELECT * FROM players")
|
||||
/// let request = SQLRequest("SELECT * FROM players WHERE id = ?", arguments: [1])
|
||||
///
|
||||
/// - parameters:
|
||||
/// - sql: An SQL query.
|
||||
/// - arguments: Optional statement arguments.
|
||||
/// - adapter: Optional RowAdapter.
|
||||
/// - cached: Defaults to false. If true, the request reuses a cached
|
||||
/// prepared statement.
|
||||
/// - returns: A SQLRequest
|
||||
public init(_ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil, cached: Bool = false) {
|
||||
self.init(sql, arguments: arguments, adapter: adapter, fromCache: cached ? .public : nil)
|
||||
}
|
||||
|
||||
/// Creates a new SQL request from any other fetch request.
|
||||
///
|
||||
/// - parameters:
|
||||
/// - db: A database connection.
|
||||
/// - request: A request.
|
||||
/// - cached: Defaults to false. If true, the request reuses a cached
|
||||
/// prepared statement.
|
||||
/// - returns: An SQLRequest
|
||||
public init<Request: FetchRequest>(_ db: Database, request: Request, cached: Bool = false) throws where Request.RowDecoder == RowDecoder {
|
||||
let (statement, adapter) = try request.prepare(db)
|
||||
self.init(statement.sql, arguments: statement.arguments, adapter: adapter, cached: cached)
|
||||
}
|
||||
|
||||
/// Creates a new SQL request from an SQL string, optional arguments, and
|
||||
/// optional row adapter.
|
||||
///
|
||||
/// let request = SQLRequest("SELECT * FROM players")
|
||||
/// let request = SQLRequest("SELECT * FROM players WHERE id = ?", arguments: [1])
|
||||
///
|
||||
/// - parameters:
|
||||
/// - sql: An SQL query.
|
||||
/// - arguments: Optional statement arguments.
|
||||
/// - adapter: Optional RowAdapter.
|
||||
/// - statementCacheName: Optional statement cache name.
|
||||
/// - returns: A SQLRequest
|
||||
init(_ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil, fromCache cache: Cache?) {
|
||||
self.sql = sql
|
||||
self.arguments = arguments
|
||||
self.adapter = adapter
|
||||
self.cache = cache
|
||||
}
|
||||
|
||||
/// A tuple that contains a prepared statement that is ready to be
|
||||
/// executed, and an eventual row adapter.
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
///
|
||||
/// :nodoc:
|
||||
public func prepare(_ db: Database) throws -> (SelectStatement, RowAdapter?) {
|
||||
let statement: SelectStatement
|
||||
switch cache {
|
||||
case .none:
|
||||
statement = try db.makeSelectStatement(sql)
|
||||
case .public?:
|
||||
statement = try db.cachedSelectStatement(sql)
|
||||
case .internal?:
|
||||
statement = try db.internalCachedSelectStatement(sql)
|
||||
}
|
||||
if let arguments = arguments {
|
||||
try statement.setArgumentsWithValidation(arguments)
|
||||
}
|
||||
return (statement, adapter)
|
||||
}
|
||||
|
||||
/// There are two statement caches: one for statements generated by the
|
||||
/// user, and one for the statements generated by GRDB. Those are separated
|
||||
/// so that GRDB has no opportunity to inadvertently modify the arguments of
|
||||
/// user's cached statements.
|
||||
enum Cache {
|
||||
/// The public cache, for library user
|
||||
case `public`
|
||||
|
||||
/// The internal cache, for grdb
|
||||
case `internal`
|
||||
}
|
||||
}
|
||||
@@ -1,622 +0,0 @@
|
||||
/// The protocol for all types that define a way to fetch database rows.
|
||||
///
|
||||
/// Requests can feed the fetching methods of any fetchable type (Row,
|
||||
/// value, record):
|
||||
///
|
||||
/// let request: Request = ...
|
||||
/// try Row.fetchCursor(db, request) // RowCursor
|
||||
/// try String.fetchAll(db, request) // [String]
|
||||
/// try Player.fetchOne(db, request) // Player?
|
||||
public protocol Request {
|
||||
/// A tuple that contains a prepared statement that is ready to be
|
||||
/// executed, and an eventual row adapter.
|
||||
func prepare(_ db: Database) throws -> (SelectStatement, RowAdapter?)
|
||||
|
||||
/// The number of rows fetched by the request.
|
||||
///
|
||||
/// Default implementation builds a naive SQL query based on the statement
|
||||
/// returned by the `prepare` method: `SELECT COUNT(*) FROM (...)`.
|
||||
///
|
||||
/// Adopting types can refine this countRequest method and return more
|
||||
/// efficient SQL.
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
func fetchCount(_ db: Database) throws -> Int
|
||||
|
||||
/// The database region that the request looks into.
|
||||
///
|
||||
/// This method has a default implementation.
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
func fetchedRegion(_ db: Database) throws -> DatabaseRegion
|
||||
}
|
||||
|
||||
extension Request {
|
||||
/// The number of rows fetched by the request.
|
||||
///
|
||||
/// This default implementation builds a naive SQL query based on the
|
||||
/// statement returned by the `prepare` method: `SELECT COUNT(*) FROM (...)`.
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
public func fetchCount(_ db: Database) throws -> Int {
|
||||
let (statement, _) = try prepare(db)
|
||||
let sql = "SELECT COUNT(*) FROM (\(statement.sql))"
|
||||
return try Int.fetchOne(db, sql, arguments: statement.arguments)!
|
||||
}
|
||||
|
||||
/// Returns an equivalent SQLRequest.
|
||||
///
|
||||
/// - parameters:
|
||||
/// - db: A database connection.
|
||||
/// - cached: Defaults to false. If true, the request reuses a cached
|
||||
/// prepared statement.
|
||||
/// - returns: An SQLRequest
|
||||
public func asSQLRequest(_ db: Database, cached: Bool = false) throws -> SQLRequest {
|
||||
let (statement, adapter) = try prepare(db)
|
||||
return SQLRequest(statement.sql, arguments: statement.arguments, adapter: adapter, cached: cached)
|
||||
}
|
||||
|
||||
/// The database region that the request looks into.
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
public func fetchedRegion(_ db: Database) throws -> DatabaseRegion {
|
||||
let (statement, _) = try prepare(db)
|
||||
return statement.fetchedRegion
|
||||
}
|
||||
}
|
||||
|
||||
extension Request {
|
||||
/// Returns a request bound to type T.
|
||||
///
|
||||
/// The returned request can fetch if the type T is fetchable (Row,
|
||||
/// value, record).
|
||||
///
|
||||
/// // Int?
|
||||
/// let maxScore = Player
|
||||
/// .select(max(scoreColumn))
|
||||
/// .asRequest(of: Int.self) // <--
|
||||
/// .fetchOne(db)
|
||||
///
|
||||
/// - parameter type: The fetched type T
|
||||
/// - returns: A typed request bound to type T.
|
||||
public func asRequest<T>(of type: T.Type) -> AnyTypedRequest<T> {
|
||||
return AnyTypedRequest(self)
|
||||
}
|
||||
|
||||
/// Returns an adapted request.
|
||||
public func adapted(_ adapter: @escaping (Database) throws -> RowAdapter) -> AdaptedRequest<Self> {
|
||||
return AdaptedRequest(self, adapter)
|
||||
}
|
||||
}
|
||||
|
||||
/// An adapted request.
|
||||
public struct AdaptedRequest<Base: Request> : Request {
|
||||
private let base: Base
|
||||
private let adapter: (Database) throws -> RowAdapter
|
||||
|
||||
/// Creates an adapted request from a base request and a closure that builds
|
||||
/// a row adapter from a database connection.
|
||||
init(_ base: Base, _ adapter: @escaping (Database) throws -> RowAdapter) {
|
||||
self.base = base
|
||||
self.adapter = adapter
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
public func prepare(_ db: Database) throws -> (SelectStatement, RowAdapter?) {
|
||||
let (statement, baseAdapter) = try base.prepare(db)
|
||||
if let baseAdapter = baseAdapter {
|
||||
return try (statement, ChainedAdapter(first: baseAdapter, second: adapter(db)))
|
||||
} else {
|
||||
return try (statement, adapter(db))
|
||||
}
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
public func fetchCount(_ db: Database) throws -> Int {
|
||||
return try base.fetchCount(db)
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
public func fetchedRegion(_ db: Database) throws -> DatabaseRegion {
|
||||
return try base.fetchedRegion(db)
|
||||
}
|
||||
}
|
||||
|
||||
/// A type-erased Request.
|
||||
///
|
||||
/// An instance of AnyRequest forwards its operations to an underlying request,
|
||||
/// hiding its specifics.
|
||||
public struct AnyRequest : Request {
|
||||
private let base: Request
|
||||
|
||||
/// Creates a new request that wraps and forwards operations to `request`.
|
||||
public init(_ request: Request) {
|
||||
base = request
|
||||
}
|
||||
|
||||
/// Creates a new request whose `prepare()` method wraps and forwards
|
||||
/// operations the argument closure.
|
||||
public init(_ prepare: @escaping (Database) throws -> (SelectStatement, RowAdapter?)) {
|
||||
struct PrepareRequest: Request {
|
||||
let base: (Database) throws -> (SelectStatement, RowAdapter?)
|
||||
func prepare(_ db: Database) throws -> (SelectStatement, RowAdapter?) {
|
||||
return try base(db)
|
||||
}
|
||||
}
|
||||
base = PrepareRequest(base: prepare)
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
public func prepare(_ db: Database) throws -> (SelectStatement, RowAdapter?) {
|
||||
return try base.prepare(db)
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
public func fetchCount(_ db: Database) throws -> Int {
|
||||
return try base.fetchCount(db)
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
public func fetchedRegion(_ db: Database) throws -> DatabaseRegion {
|
||||
return try base.fetchedRegion(db)
|
||||
}
|
||||
}
|
||||
|
||||
/// A Request built from raw SQL.
|
||||
public struct SQLRequest : Request {
|
||||
public let sql: String
|
||||
public let arguments: StatementArguments?
|
||||
public let adapter: RowAdapter?
|
||||
private let cache: Cache?
|
||||
|
||||
/// Creates a new request from an SQL string, optional arguments, and
|
||||
/// optional row adapter.
|
||||
///
|
||||
/// let request = SQLRequest("SELECT * FROM players")
|
||||
/// let request = SQLRequest("SELECT * FROM players WHERE id = ?", arguments: [1])
|
||||
///
|
||||
/// - parameters:
|
||||
/// - sql: An SQL query.
|
||||
/// - arguments: Optional statement arguments.
|
||||
/// - adapter: Optional RowAdapter.
|
||||
/// - cached: Defaults to false. If true, the request reuses a cached
|
||||
/// prepared statement.
|
||||
/// - returns: A SQLRequest
|
||||
public init(_ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil, cached: Bool = false) {
|
||||
self.init(sql, arguments: arguments, adapter: adapter, fromCache: cached ? .public : nil)
|
||||
}
|
||||
|
||||
/// Creates a new request from an SQL string, optional arguments, and
|
||||
/// optional row adapter.
|
||||
///
|
||||
/// let request = SQLRequest("SELECT * FROM players")
|
||||
/// let request = SQLRequest("SELECT * FROM players WHERE id = ?", arguments: [1])
|
||||
///
|
||||
/// - parameters:
|
||||
/// - sql: An SQL query.
|
||||
/// - arguments: Optional statement arguments.
|
||||
/// - adapter: Optional RowAdapter.
|
||||
/// - statementCacheName: Optional statement cache name.
|
||||
/// - returns: A SQLRequest
|
||||
init(_ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil, fromCache cache: Cache?) {
|
||||
self.sql = sql
|
||||
self.arguments = arguments
|
||||
self.adapter = adapter
|
||||
self.cache = cache
|
||||
}
|
||||
|
||||
/// A tuple that contains a prepared statement that is ready to be
|
||||
/// executed, and an eventual row adapter.
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
///
|
||||
/// :nodoc:
|
||||
public func prepare(_ db: Database) throws -> (SelectStatement, RowAdapter?) {
|
||||
let statement: SelectStatement
|
||||
switch cache {
|
||||
case .none:
|
||||
statement = try db.makeSelectStatement(sql)
|
||||
case .public?:
|
||||
statement = try db.cachedSelectStatement(sql)
|
||||
case .internal?:
|
||||
statement = try db.internalCachedSelectStatement(sql)
|
||||
}
|
||||
if let arguments = arguments {
|
||||
try statement.setArgumentsWithValidation(arguments)
|
||||
}
|
||||
return (statement, adapter)
|
||||
}
|
||||
|
||||
/// There are two statement caches: one for statements generated by the
|
||||
/// user, and one for the statements generated by GRDB. Those are separated
|
||||
/// so that GRDB has no opportunity to inadvertently modify the arguments of
|
||||
/// user's cached statements.
|
||||
enum Cache {
|
||||
/// The public cache, for library user
|
||||
case `public`
|
||||
|
||||
/// The internal cache, for grdb
|
||||
case `internal`
|
||||
}
|
||||
}
|
||||
|
||||
/// The protocol for requests that know how to decode database rows.
|
||||
///
|
||||
/// Typed requests can fetch if their associated type RowDecoder is able to
|
||||
/// decode rows (Row, value, record)
|
||||
///
|
||||
/// struct Player: RowConvertible { ... }
|
||||
/// let request: ... // Some TypedRequest that fetches Player
|
||||
/// try request.fetchCursor(db) // Cursor of Player
|
||||
/// try request.fetchAll(db) // [Player]
|
||||
/// try request.fetchOne(db) // Player?
|
||||
public protocol TypedRequest : Request {
|
||||
|
||||
/// The type that can convert raw database rows to fetched values
|
||||
associatedtype RowDecoder
|
||||
}
|
||||
|
||||
extension TypedRequest {
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
///
|
||||
/// Returns an adapted typed request.
|
||||
public func adapted(_ adapter: @escaping (Database) throws -> RowAdapter) -> AdaptedTypedRequest<Self> {
|
||||
return AdaptedTypedRequest(self, adapter)
|
||||
}
|
||||
}
|
||||
|
||||
/// An adapted typed request.
|
||||
public struct AdaptedTypedRequest<Base: TypedRequest> : TypedRequest {
|
||||
/// The type that can convert raw database rows to fetched values
|
||||
public typealias RowDecoder = Base.RowDecoder
|
||||
|
||||
private let base: AdaptedRequest<Base>
|
||||
|
||||
/// Creates an adapted request from a base request and a closure that builds
|
||||
/// a row adapter from a database connection.
|
||||
init(_ base: Base, _ adapter: @escaping (Database) throws -> RowAdapter) {
|
||||
self.base = AdaptedRequest(base, adapter)
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
public func prepare(_ db: Database) throws -> (SelectStatement, RowAdapter?) {
|
||||
return try base.prepare(db)
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
public func fetchCount(_ db: Database) throws -> Int {
|
||||
return try base.fetchCount(db)
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
public func fetchedRegion(_ db: Database) throws -> DatabaseRegion {
|
||||
return try base.fetchedRegion(db)
|
||||
}
|
||||
}
|
||||
|
||||
/// A type-erased TypedRequest.
|
||||
///
|
||||
/// An instance of AnyTypedRequest forwards its operations to an underlying
|
||||
/// typed request, hiding its specifics.
|
||||
public struct AnyTypedRequest<T> : TypedRequest {
|
||||
/// The type that can convert raw database rows to fetched values
|
||||
public typealias RowDecoder = T
|
||||
private let base: Request
|
||||
|
||||
/// Support for Request.asRequest(of:)
|
||||
/// Not public because not type-safe.
|
||||
fileprivate init(_ request: Request) {
|
||||
base = request
|
||||
}
|
||||
|
||||
/// Creates a new request that wraps and forwards operations to `request`.
|
||||
public init<Request>(_ request: Request) where Request: TypedRequest, Request.RowDecoder == RowDecoder {
|
||||
base = request
|
||||
}
|
||||
|
||||
/// Creates a new request whose `prepare()` method wraps and forwards
|
||||
/// operations the argument closure.
|
||||
public init(_ prepare: @escaping (Database) throws -> (SelectStatement, RowAdapter?)) {
|
||||
base = AnyRequest(prepare)
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
public func prepare(_ db: Database) throws -> (SelectStatement, RowAdapter?) {
|
||||
return try base.prepare(db)
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
public func fetchCount(_ db: Database) throws -> Int {
|
||||
return try base.fetchCount(db)
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
public func fetchedRegion(_ db: Database) throws -> DatabaseRegion {
|
||||
return try base.fetchedRegion(db)
|
||||
}
|
||||
}
|
||||
|
||||
extension TypedRequest where RowDecoder: RowConvertible {
|
||||
|
||||
// MARK: Fetching Record and RowConvertible
|
||||
|
||||
/// A cursor over fetched records.
|
||||
///
|
||||
/// let request: ... // Some TypedRequest that fetches Player
|
||||
/// let players = try request.fetchCursor(db) // Cursor of Player
|
||||
/// while let player = try players.next() { // Player
|
||||
/// ...
|
||||
/// }
|
||||
///
|
||||
/// If the database is modified during the cursor iteration, the remaining
|
||||
/// elements are undefined.
|
||||
///
|
||||
/// The cursor must be iterated in a protected dispath queue.
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
/// - returns: A cursor over fetched records.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public func fetchCursor(_ db: Database) throws -> RecordCursor<RowDecoder> {
|
||||
return try RowDecoder.fetchCursor(db, self)
|
||||
}
|
||||
|
||||
/// An array of fetched records.
|
||||
///
|
||||
/// let request: ... // Some TypedRequest that fetches Player
|
||||
/// let players = try request.fetchAll(db) // [Player]
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
/// - returns: An array of records.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public func fetchAll(_ db: Database) throws -> [RowDecoder] {
|
||||
return try RowDecoder.fetchAll(db, self)
|
||||
}
|
||||
|
||||
/// The first fetched record.
|
||||
///
|
||||
/// let request: ... // Some TypedRequest that fetches Player
|
||||
/// let player = try request.fetchOne(db) // Player?
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
/// - returns: An optional record.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public func fetchOne(_ db: Database) throws -> RowDecoder? {
|
||||
return try RowDecoder.fetchOne(db, self)
|
||||
}
|
||||
}
|
||||
|
||||
extension TypedRequest where RowDecoder: DatabaseValueConvertible {
|
||||
|
||||
// MARK: Fetching Values
|
||||
|
||||
/// A cursor over fetched values.
|
||||
///
|
||||
/// let request: ... // Some TypedRequest that fetches String
|
||||
/// let strings = try request.fetchCursor(db) // Cursor of String
|
||||
/// while let string = try strings.next() { // String
|
||||
/// ...
|
||||
/// }
|
||||
///
|
||||
/// If the database is modified during the cursor iteration, the remaining
|
||||
/// elements are undefined.
|
||||
///
|
||||
/// The cursor must be iterated in a protected dispath queue.
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
/// - returns: A cursor over fetched values.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public func fetchCursor(_ db: Database) throws -> DatabaseValueCursor<RowDecoder> {
|
||||
return try RowDecoder.fetchCursor(db, self)
|
||||
}
|
||||
|
||||
/// An array of fetched values.
|
||||
///
|
||||
/// let request: ... // Some TypedRequest that fetches String
|
||||
/// let strings = try request.fetchAll(db) // [String]
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
/// - returns: An array of values.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public func fetchAll(_ db: Database) throws -> [RowDecoder] {
|
||||
return try RowDecoder.fetchAll(db, self)
|
||||
}
|
||||
|
||||
/// The first fetched value.
|
||||
///
|
||||
/// The result is nil if the request returns no row, or if no value can be
|
||||
/// extracted from the first row.
|
||||
///
|
||||
/// let request: ... // Some TypedRequest that fetches String
|
||||
/// let string = try request.fetchOne(db) // String?
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
/// - returns: An optional value.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public func fetchOne(_ db: Database) throws -> RowDecoder? {
|
||||
return try RowDecoder.fetchOne(db, self)
|
||||
}
|
||||
}
|
||||
|
||||
extension TypedRequest where RowDecoder: DatabaseValueConvertible & StatementColumnConvertible {
|
||||
|
||||
// MARK: Fetching Values
|
||||
|
||||
/// A cursor over fetched values.
|
||||
///
|
||||
/// let request: ... // Some TypedRequest that fetches String
|
||||
/// let strings = try request.fetchCursor(db) // Cursor of String
|
||||
/// while let string = try strings.next() { // String
|
||||
/// ...
|
||||
/// }
|
||||
///
|
||||
/// If the database is modified during the cursor iteration, the remaining
|
||||
/// elements are undefined.
|
||||
///
|
||||
/// The cursor must be iterated in a protected dispath queue.
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
/// - returns: A cursor over fetched values.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public func fetchCursor(_ db: Database) throws -> ColumnCursor<RowDecoder> {
|
||||
return try RowDecoder.fetchCursor(db, self)
|
||||
}
|
||||
|
||||
/// An array of fetched values.
|
||||
///
|
||||
/// let request: ... // Some TypedRequest that fetches String
|
||||
/// let strings = try request.fetchAll(db) // [String]
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
/// - returns: An array of values.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public func fetchAll(_ db: Database) throws -> [RowDecoder] {
|
||||
return try RowDecoder.fetchAll(db, self)
|
||||
}
|
||||
|
||||
/// The first fetched value.
|
||||
///
|
||||
/// The result is nil if the request returns no row, or if no value can be
|
||||
/// extracted from the first row.
|
||||
///
|
||||
/// let request: ... // Some TypedRequest that fetches String
|
||||
/// let string = try request.fetchOne(db) // String?
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
/// - returns: An optional value.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public func fetchOne(_ db: Database) throws -> RowDecoder? {
|
||||
return try RowDecoder.fetchOne(db, self)
|
||||
}
|
||||
}
|
||||
|
||||
extension TypedRequest where RowDecoder: _OptionalProtocol, RowDecoder._Wrapped: DatabaseValueConvertible {
|
||||
|
||||
// MARK: Fetching Optional values
|
||||
|
||||
/// A cursor over fetched optional values.
|
||||
///
|
||||
/// let request: ... // Some TypedRequest that fetches Optional<String>
|
||||
/// let strings = try request.fetchCursor(db) // Cursor of String?
|
||||
/// while let string = try strings.next() { // String?
|
||||
/// ...
|
||||
/// }
|
||||
///
|
||||
/// If the database is modified during the cursor iteration, the remaining
|
||||
/// elements are undefined.
|
||||
///
|
||||
/// The cursor must be iterated in a protected dispath queue.
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
/// - returns: A cursor over fetched values.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public func fetchCursor(_ db: Database) throws -> NullableDatabaseValueCursor<RowDecoder._Wrapped> {
|
||||
return try Optional<RowDecoder._Wrapped>.fetchCursor(db, self)
|
||||
}
|
||||
|
||||
/// An array of fetched optional values.
|
||||
///
|
||||
/// let request: ... // Some TypedRequest that fetches Optional<String>
|
||||
/// let strings = try request.fetchAll(db) // [String?]
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
/// - returns: An array of values.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public func fetchAll(_ db: Database) throws -> [RowDecoder._Wrapped?] {
|
||||
return try Optional<RowDecoder._Wrapped>.fetchAll(db, self)
|
||||
}
|
||||
}
|
||||
|
||||
extension TypedRequest where RowDecoder: _OptionalProtocol, RowDecoder._Wrapped: DatabaseValueConvertible & StatementColumnConvertible {
|
||||
|
||||
// MARK: Fetching Optional values
|
||||
|
||||
/// A cursor over fetched optional values.
|
||||
///
|
||||
/// let request: ... // Some TypedRequest that fetches Optional<String>
|
||||
/// let strings = try request.fetchCursor(db) // Cursor of String?
|
||||
/// while let string = try strings.next() { // String?
|
||||
/// ...
|
||||
/// }
|
||||
///
|
||||
/// If the database is modified during the cursor iteration, the remaining
|
||||
/// elements are undefined.
|
||||
///
|
||||
/// The cursor must be iterated in a protected dispath queue.
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
/// - returns: A cursor over fetched values.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public func fetchCursor(_ db: Database) throws -> NullableColumnCursor<RowDecoder._Wrapped> {
|
||||
return try Optional<RowDecoder._Wrapped>.fetchCursor(db, self)
|
||||
}
|
||||
|
||||
/// An array of fetched optional values.
|
||||
///
|
||||
/// let request: ... // Some TypedRequest that fetches Optional<String>
|
||||
/// let strings = try request.fetchAll(db) // [String?]
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
/// - returns: An array of values.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public func fetchAll(_ db: Database) throws -> [RowDecoder._Wrapped?] {
|
||||
return try Optional<RowDecoder._Wrapped>.fetchAll(db, self)
|
||||
}
|
||||
}
|
||||
|
||||
extension TypedRequest where RowDecoder: Row {
|
||||
|
||||
// MARK: Fetching Rows
|
||||
|
||||
/// A cursor over fetched rows.
|
||||
///
|
||||
/// let request: ... // Some TypedRequest that fetches Row
|
||||
/// let rows = try request.fetchCursor(db) // RowCursor
|
||||
/// while let row = try rows.next() { // Row
|
||||
/// let id: Int64 = row[0]
|
||||
/// let name: String = row[1]
|
||||
/// }
|
||||
///
|
||||
/// Fetched rows are reused during the cursor iteration: don't turn a row
|
||||
/// cursor into an array with `Array(rows)` or `rows.filter { ... }` since
|
||||
/// you would not get the distinct rows you expect. Use `Row.fetchAll(...)`
|
||||
/// instead.
|
||||
///
|
||||
/// For the same reason, make sure you make a copy whenever you extract a
|
||||
/// row for later use: `row.copy()`.
|
||||
///
|
||||
/// If the database is modified during the cursor iteration, the remaining
|
||||
/// elements are undefined.
|
||||
///
|
||||
/// The cursor must be iterated in a protected dispath queue.
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
/// - returns: A cursor over fetched rows.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public func fetchCursor(_ db: Database) throws -> RowCursor {
|
||||
return try Row.fetchCursor(db, self)
|
||||
}
|
||||
|
||||
/// An array of fetched rows.
|
||||
///
|
||||
/// let request: ... // Some TypedRequest that fetches Row
|
||||
/// let rows = try request.fetchAll(db)
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
/// - returns: An array of fetched rows.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public func fetchAll(_ db: Database) throws -> [Row] {
|
||||
return try Row.fetchAll(db, self)
|
||||
}
|
||||
|
||||
/// The first fetched row.
|
||||
///
|
||||
/// let request: ... // Some TypedRequest that fetches Row
|
||||
/// let row = try request.fetchOne(db)
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
/// - returns: A,n optional rows.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public func fetchOne(_ db: Database) throws -> Row? {
|
||||
return try Row.fetchOne(db, self)
|
||||
}
|
||||
}
|
||||
+64
-70
@@ -652,73 +652,6 @@ extension Row {
|
||||
}
|
||||
}
|
||||
|
||||
extension Row {
|
||||
|
||||
// MARK: - Fetching From Request
|
||||
|
||||
/// Returns a cursor over rows fetched from a fetch request.
|
||||
///
|
||||
/// let idColumn = Column("id")
|
||||
/// let nameColumn = Column("name")
|
||||
/// let request = Player.select(idColumn, nameColumn)
|
||||
/// let rows = try Row.fetchCursor(db) // RowCursor
|
||||
/// while let row = try rows.next() { // Row
|
||||
/// let id: Int64 = row[0]
|
||||
/// let name: String = row[1]
|
||||
/// }
|
||||
///
|
||||
/// Fetched rows are reused during the cursor iteration: don't turn a row
|
||||
/// cursor into an array with `Array(rows)` or `rows.filter { ... }` since
|
||||
/// you would not get the distinct rows you expect. Use `Row.fetchAll(...)`
|
||||
/// instead.
|
||||
///
|
||||
/// For the same reason, make sure you make a copy whenever you extract a
|
||||
/// row for later use: `row.copy()`.
|
||||
///
|
||||
/// If the database is modified during the cursor iteration, the remaining
|
||||
/// elements are undefined.
|
||||
///
|
||||
/// The cursor must be iterated in a protected dispath queue.
|
||||
///
|
||||
/// - parameters:
|
||||
/// - db: A database connection.
|
||||
/// - request: A fetch request.
|
||||
/// - returns: A cursor over fetched rows.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public static func fetchCursor(_ db: Database, _ request: Request) throws -> RowCursor {
|
||||
let (statement, adapter) = try request.prepare(db)
|
||||
return try fetchCursor(statement, adapter: adapter)
|
||||
}
|
||||
|
||||
/// Returns an array of rows fetched from a fetch request.
|
||||
///
|
||||
/// let idColumn = Column("id")
|
||||
/// let nameColumn = Column("name")
|
||||
/// let request = Player.select(idColumn, nameColumn)
|
||||
/// let rows = try Row.fetchAll(db, request)
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public static func fetchAll(_ db: Database, _ request: Request) throws -> [Row] {
|
||||
let (statement, adapter) = try request.prepare(db)
|
||||
return try fetchAll(statement, adapter: adapter)
|
||||
}
|
||||
|
||||
/// Returns a single row fetched from a fetch request.
|
||||
///
|
||||
/// let idColumn = Column("id")
|
||||
/// let nameColumn = Column("name")
|
||||
/// let request = Player.select(idColumn, nameColumn)
|
||||
/// let row = try Row.fetchOne(db, request)
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public static func fetchOne(_ db: Database, _ request: Request) throws -> Row? {
|
||||
let (statement, adapter) = try request.prepare(db)
|
||||
return try fetchOne(statement, adapter: adapter)
|
||||
}
|
||||
}
|
||||
|
||||
extension Row {
|
||||
|
||||
// MARK: - Fetching From SQL
|
||||
@@ -752,7 +685,7 @@ extension Row {
|
||||
/// - returns: A cursor over fetched rows.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public static func fetchCursor(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> RowCursor {
|
||||
return try fetchCursor(db, SQLRequest(sql, arguments: arguments, adapter: adapter))
|
||||
return try SQLRequest<Row>(sql, arguments: arguments, adapter: adapter).fetchCursor(db)
|
||||
}
|
||||
|
||||
/// Returns an array of rows fetched from an SQL query.
|
||||
@@ -767,7 +700,7 @@ extension Row {
|
||||
/// - returns: An array of rows.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public static func fetchAll(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> [Row] {
|
||||
return try fetchAll(db, SQLRequest(sql, arguments: arguments, adapter: adapter))
|
||||
return try SQLRequest<Row>(sql, arguments: arguments, adapter: adapter).fetchAll(db)
|
||||
}
|
||||
|
||||
/// Returns a single row fetched from an SQL query.
|
||||
@@ -782,7 +715,68 @@ extension Row {
|
||||
/// - returns: An optional row.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public static func fetchOne(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> Row? {
|
||||
return try fetchOne(db, SQLRequest(sql, arguments: arguments, adapter: adapter))
|
||||
return try SQLRequest<Row>(sql, arguments: arguments, adapter: adapter).fetchOne(db)
|
||||
}
|
||||
}
|
||||
|
||||
extension FetchRequest where RowDecoder: Row {
|
||||
|
||||
// MARK: Fetching Rows
|
||||
|
||||
/// A cursor over fetched rows.
|
||||
///
|
||||
/// let request: ... // Some TypedRequest that fetches Row
|
||||
/// let rows = try request.fetchCursor(db) // RowCursor
|
||||
/// while let row = try rows.next() { // Row
|
||||
/// let id: Int64 = row[0]
|
||||
/// let name: String = row[1]
|
||||
/// }
|
||||
///
|
||||
/// Fetched rows are reused during the cursor iteration: don't turn a row
|
||||
/// cursor into an array with `Array(rows)` or `rows.filter { ... }` since
|
||||
/// you would not get the distinct rows you expect. Use `Row.fetchAll(...)`
|
||||
/// instead.
|
||||
///
|
||||
/// For the same reason, make sure you make a copy whenever you extract a
|
||||
/// row for later use: `row.copy()`.
|
||||
///
|
||||
/// If the database is modified during the cursor iteration, the remaining
|
||||
/// elements are undefined.
|
||||
///
|
||||
/// The cursor must be iterated in a protected dispath queue.
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
/// - returns: A cursor over fetched rows.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public func fetchCursor(_ db: Database) throws -> RowCursor {
|
||||
let (statement, adapter) = try prepare(db)
|
||||
return try Row.fetchCursor(statement, adapter: adapter)
|
||||
}
|
||||
|
||||
/// An array of fetched rows.
|
||||
///
|
||||
/// let request: ... // Some TypedRequest that fetches Row
|
||||
/// let rows = try request.fetchAll(db)
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
/// - returns: An array of fetched rows.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public func fetchAll(_ db: Database) throws -> [Row] {
|
||||
let (statement, adapter) = try prepare(db)
|
||||
return try Row.fetchAll(statement, adapter: adapter)
|
||||
}
|
||||
|
||||
/// The first fetched row.
|
||||
///
|
||||
/// let request: ... // Some TypedRequest that fetches Row
|
||||
/// let row = try request.fetchOne(db)
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
/// - returns: A,n optional rows.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public func fetchOne(_ db: Database) throws -> Row? {
|
||||
let (statement, adapter) = try prepare(db)
|
||||
return try Row.fetchOne(statement, adapter: adapter)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -225,64 +225,6 @@ extension DatabaseValueConvertible where Self: StatementColumnConvertible {
|
||||
}
|
||||
}
|
||||
|
||||
extension DatabaseValueConvertible where Self: StatementColumnConvertible {
|
||||
|
||||
// MARK: Fetching From Request
|
||||
|
||||
/// Returns a cursor over values fetched from a fetch request.
|
||||
///
|
||||
/// let nameColumn = Column("name")
|
||||
/// let request = Player.select(nameColumn)
|
||||
/// let names = try String.fetchCursor(db, request) // Cursor of String
|
||||
/// while let name = try names.next() { // String
|
||||
/// ...
|
||||
/// }
|
||||
///
|
||||
/// If the database is modified during the cursor iteration, the remaining
|
||||
/// elements are undefined.
|
||||
///
|
||||
/// The cursor must be iterated in a protected dispath queue.
|
||||
///
|
||||
/// - parameters:
|
||||
/// - db: A database connection.
|
||||
/// - request: A fetch request.
|
||||
/// - returns: A cursor over fetched values.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public static func fetchCursor(_ db: Database, _ request: Request) throws -> ColumnCursor<Self> {
|
||||
let (statement, adapter) = try request.prepare(db)
|
||||
return try fetchCursor(statement, adapter: adapter)
|
||||
}
|
||||
|
||||
/// Returns an array of values fetched from a fetch request.
|
||||
///
|
||||
/// let nameColumn = Column("name")
|
||||
/// let request = Player.select(nameColumn)
|
||||
/// let names = try String.fetchAll(db, request) // [String]
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public static func fetchAll(_ db: Database, _ request: Request) throws -> [Self] {
|
||||
let (statement, adapter) = try request.prepare(db)
|
||||
return try fetchAll(statement, adapter: adapter)
|
||||
}
|
||||
|
||||
/// Returns a single value fetched from a fetch request.
|
||||
///
|
||||
/// The result is nil if the query returns no row, or if no value can be
|
||||
/// extracted from the first row.
|
||||
///
|
||||
/// let nameColumn = Column("name")
|
||||
/// let request = Player.select(nameColumn)
|
||||
/// let name = try String.fetchOne(db, request) // String?
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public static func fetchOne(_ db: Database, _ request: Request) throws -> Self? {
|
||||
let (statement, adapter) = try request.prepare(db)
|
||||
return try fetchOne(statement, adapter: adapter)
|
||||
}
|
||||
}
|
||||
|
||||
extension DatabaseValueConvertible where Self: StatementColumnConvertible {
|
||||
|
||||
// MARK: Fetching From SQL
|
||||
@@ -307,7 +249,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(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> ColumnCursor<Self> {
|
||||
return try fetchCursor(db, SQLRequest(sql, arguments: arguments, adapter: adapter))
|
||||
return try SQLRequest<Self>(sql, arguments: arguments, adapter: adapter).fetchCursor(db)
|
||||
}
|
||||
|
||||
/// Returns an array of values fetched from an SQL query.
|
||||
@@ -322,7 +264,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(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> [Self] {
|
||||
return try fetchAll(db, SQLRequest(sql, arguments: arguments, adapter: adapter))
|
||||
return try SQLRequest<Self>(sql, arguments: arguments, adapter: adapter).fetchAll(db)
|
||||
}
|
||||
|
||||
/// Returns a single value fetched from an SQL query.
|
||||
@@ -337,10 +279,64 @@ extension DatabaseValueConvertible where Self: StatementColumnConvertible {
|
||||
/// - returns: An optional value.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public static func fetchOne(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> Self? {
|
||||
return try fetchOne(db, SQLRequest(sql, arguments: arguments, adapter: adapter))
|
||||
return try SQLRequest<Self>(sql, arguments: arguments, adapter: adapter).fetchOne(db)
|
||||
}
|
||||
}
|
||||
|
||||
extension FetchRequest where RowDecoder: DatabaseValueConvertible & StatementColumnConvertible {
|
||||
|
||||
// MARK: Fetching Values
|
||||
|
||||
/// A cursor over fetched values.
|
||||
///
|
||||
/// let request: ... // Some TypedRequest that fetches String
|
||||
/// let strings = try request.fetchCursor(db) // Cursor of String
|
||||
/// while let string = try strings.next() { // String
|
||||
/// ...
|
||||
/// }
|
||||
///
|
||||
/// If the database is modified during the cursor iteration, the remaining
|
||||
/// elements are undefined.
|
||||
///
|
||||
/// The cursor must be iterated in a protected dispath queue.
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
/// - returns: A cursor over fetched values.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public func fetchCursor(_ db: Database) throws -> ColumnCursor<RowDecoder> {
|
||||
let (statement, adapter) = try prepare(db)
|
||||
return try RowDecoder.fetchCursor(statement, adapter: adapter)
|
||||
}
|
||||
|
||||
/// An array of fetched values.
|
||||
///
|
||||
/// let request: ... // Some TypedRequest that fetches String
|
||||
/// let strings = try request.fetchAll(db) // [String]
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
/// - returns: An array of values.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public func fetchAll(_ db: Database) throws -> [RowDecoder] {
|
||||
let (statement, adapter) = try prepare(db)
|
||||
return try RowDecoder.fetchAll(statement, adapter: adapter)
|
||||
}
|
||||
|
||||
/// The first fetched value.
|
||||
///
|
||||
/// The result is nil if the request returns no row, or if no value can be
|
||||
/// extracted from the first row.
|
||||
///
|
||||
/// let request: ... // Some TypedRequest that fetches String
|
||||
/// let string = try request.fetchOne(db) // String?
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
/// - returns: An optional value.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public func fetchOne(_ db: Database) throws -> RowDecoder? {
|
||||
let (statement, adapter) = try prepare(db)
|
||||
return try RowDecoder.fetchOne(statement, adapter: adapter)
|
||||
}
|
||||
}
|
||||
|
||||
/// Swift's Optional comes with built-in methods that allow to fetch cursors
|
||||
/// and arrays of optional DatabaseValueConvertible:
|
||||
@@ -396,48 +392,6 @@ extension Optional where Wrapped: DatabaseValueConvertible & StatementColumnConv
|
||||
}
|
||||
}
|
||||
|
||||
extension Optional where Wrapped: DatabaseValueConvertible & StatementColumnConvertible {
|
||||
|
||||
// MARK: Fetching From Request
|
||||
|
||||
/// Returns a cursor over optional values fetched from a fetch request.
|
||||
///
|
||||
/// let nameColumn = Column("name")
|
||||
/// let request = Player.select(nameColumn)
|
||||
/// let names = try Optional<String>.fetchCursor(db, request) // Cursor of String?
|
||||
/// while let name = try names.next() { // String?
|
||||
/// ...
|
||||
/// }
|
||||
///
|
||||
/// If the database is modified during the cursor iteration, the remaining
|
||||
/// elements are undefined.
|
||||
///
|
||||
/// The cursor must be iterated in a protected dispath queue.
|
||||
///
|
||||
/// - parameters:
|
||||
/// - db: A database connection.
|
||||
/// - requet: A fetch request.
|
||||
/// - returns: A cursor over fetched optional values.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public static func fetchCursor(_ db: Database, _ request: Request) throws -> NullableColumnCursor<Wrapped> {
|
||||
let (statement, adapter) = try request.prepare(db)
|
||||
return try fetchCursor(statement, adapter: adapter)
|
||||
}
|
||||
|
||||
/// Returns an array of optional values fetched from a fetch request.
|
||||
///
|
||||
/// let nameColumn = Column("name")
|
||||
/// let request = Player.select(nameColumn)
|
||||
/// let names = try Optional<String>.fetchAll(db, request) // [String?]
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public static func fetchAll(_ db: Database, _ request: Request) throws -> [Wrapped?] {
|
||||
let (statement, adapter) = try request.prepare(db)
|
||||
return try fetchAll(statement, adapter: adapter)
|
||||
}
|
||||
}
|
||||
|
||||
extension Optional where Wrapped: DatabaseValueConvertible & StatementColumnConvertible {
|
||||
|
||||
// MARK: Fetching From SQL
|
||||
@@ -462,7 +416,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(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> NullableColumnCursor<Wrapped> {
|
||||
return try fetchCursor(db, SQLRequest(sql, arguments: arguments, adapter: adapter))
|
||||
return try SQLRequest<Wrapped?>(sql, arguments: arguments, adapter: adapter).fetchCursor(db)
|
||||
}
|
||||
|
||||
/// Returns an array of optional values fetched from an SQL query.
|
||||
@@ -477,6 +431,45 @@ 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(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> [Wrapped?] {
|
||||
return try fetchAll(db, SQLRequest(sql, arguments: arguments, adapter: adapter))
|
||||
return try SQLRequest<Wrapped?>(sql, arguments: arguments, adapter: adapter).fetchAll(db)
|
||||
}
|
||||
}
|
||||
|
||||
extension FetchRequest where RowDecoder: _OptionalProtocol, RowDecoder._Wrapped: DatabaseValueConvertible & StatementColumnConvertible {
|
||||
|
||||
// MARK: Fetching Optional values
|
||||
|
||||
/// A cursor over fetched optional values.
|
||||
///
|
||||
/// let request: ... // Some TypedRequest that fetches Optional<String>
|
||||
/// let strings = try request.fetchCursor(db) // Cursor of String?
|
||||
/// while let string = try strings.next() { // String?
|
||||
/// ...
|
||||
/// }
|
||||
///
|
||||
/// If the database is modified during the cursor iteration, the remaining
|
||||
/// elements are undefined.
|
||||
///
|
||||
/// The cursor must be iterated in a protected dispath queue.
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
/// - returns: A cursor over fetched values.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public func fetchCursor(_ db: Database) throws -> NullableColumnCursor<RowDecoder._Wrapped> {
|
||||
let (statement, adapter) = try prepare(db)
|
||||
return try Optional<RowDecoder._Wrapped>.fetchCursor(statement, adapter: adapter)
|
||||
}
|
||||
|
||||
/// An array of fetched optional values.
|
||||
///
|
||||
/// let request: ... // Some TypedRequest that fetches Optional<String>
|
||||
/// let strings = try request.fetchAll(db) // [String?]
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
/// - returns: An array of values.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public func fetchAll(_ db: Database) throws -> [RowDecoder._Wrapped?] {
|
||||
let (statement, adapter) = try prepare(db)
|
||||
return try Optional<RowDecoder._Wrapped>.fetchAll(statement, adapter: adapter)
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@ extension Row {
|
||||
@available(*, unavailable, renamed:"fetchCursor")
|
||||
public static func fetch(_ statement: SelectStatement, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) -> Any { preconditionFailure() }
|
||||
@available(*, unavailable, renamed:"fetchCursor")
|
||||
public static func fetch(_ db: Database, _ request: Request) -> Any { preconditionFailure() }
|
||||
public static func fetch<Request: FetchRequest>(_ db: Database, _ request: Request) -> Any { preconditionFailure() }
|
||||
@available(*, unavailable, renamed:"fetchCursor")
|
||||
public static func fetch(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) -> Any { preconditionFailure() }
|
||||
}
|
||||
@@ -11,7 +11,7 @@ extension DatabaseValueConvertible {
|
||||
@available(*, unavailable, renamed:"fetchCursor")
|
||||
public static func fetch(_ statement: SelectStatement, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) -> Any { preconditionFailure() }
|
||||
@available(*, unavailable, renamed:"fetchCursor")
|
||||
public static func fetch(_ db: Database, _ request: Request) -> Any { preconditionFailure() }
|
||||
public static func fetch<Request: FetchRequest>(_ db: Database, _ request: Request) -> Any { preconditionFailure() }
|
||||
@available(*, unavailable, renamed:"fetchCursor")
|
||||
public static func fetch(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) -> Any { preconditionFailure() }
|
||||
}
|
||||
@@ -20,7 +20,7 @@ extension Optional where Wrapped: DatabaseValueConvertible {
|
||||
@available(*, unavailable, renamed:"fetchCursor")
|
||||
public static func fetch(_ statement: SelectStatement, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) -> Any { preconditionFailure() }
|
||||
@available(*, unavailable, renamed:"fetchCursor")
|
||||
public static func fetch(_ db: Database, _ request: Request) -> Any { preconditionFailure() }
|
||||
public static func fetch<Request: FetchRequest>(_ db: Database, _ request: Request) -> Any { preconditionFailure() }
|
||||
@available(*, unavailable, renamed:"fetchCursor")
|
||||
public static func fetch(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) -> Any { preconditionFailure() }
|
||||
}
|
||||
@@ -34,7 +34,7 @@ extension RowConvertible {
|
||||
@available(*, unavailable, renamed:"fetchCursor")
|
||||
public static func fetch(_ statement: SelectStatement, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) -> Any { preconditionFailure() }
|
||||
@available(*, unavailable, renamed:"fetchCursor")
|
||||
public static func fetch(_ db: Database, _ request: Request) -> Any { preconditionFailure() }
|
||||
public static func fetch<Request: FetchRequest>(_ db: Database, _ request: Request) -> Any { preconditionFailure() }
|
||||
@available(*, unavailable, renamed:"fetchCursor")
|
||||
public static func fetch(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) -> Any { preconditionFailure() }
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
extension Request {
|
||||
extension FetchRequest {
|
||||
@available(*, unavailable, renamed:"asRequest(of:)")
|
||||
public func bound<T>(to type: T.Type) -> AnyTypedRequest<T> { preconditionFailure() }
|
||||
public func bound<T>(to type: T.Type) -> AnyFetchRequest<T> { preconditionFailure() }
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
@available(*, unavailable, renamed:"FetchRequest")
|
||||
public typealias Request = FetchRequest
|
||||
|
||||
+10
-11
@@ -1,5 +1,3 @@
|
||||
// MARK: - QueryInterfaceSelectQueryDefinition
|
||||
|
||||
struct DatabasePromise<T> {
|
||||
let resolve: (Database) throws -> T
|
||||
|
||||
@@ -18,7 +16,7 @@ struct DatabasePromise<T> {
|
||||
}
|
||||
}
|
||||
|
||||
struct QueryInterfaceSelectQueryDefinition {
|
||||
struct QueryInterfaceQuery {
|
||||
var selection: [SQLSelectable]
|
||||
var isDistinct: Bool
|
||||
var source: SQLSource?
|
||||
@@ -51,7 +49,7 @@ struct QueryInterfaceSelectQueryDefinition {
|
||||
self.limit = limit
|
||||
}
|
||||
|
||||
func mapWhereExpression(_ transform: @escaping (Database, SQLExpression?) throws -> SQLExpression?) -> QueryInterfaceSelectQueryDefinition {
|
||||
func mapWhereExpression(_ transform: @escaping (Database, SQLExpression?) throws -> SQLExpression?) -> QueryInterfaceQuery {
|
||||
var query = self
|
||||
query.wherePromise = query.wherePromise.map(transform)
|
||||
return query
|
||||
@@ -160,7 +158,7 @@ struct QueryInterfaceSelectQueryDefinition {
|
||||
}
|
||||
|
||||
/// Remove ordering
|
||||
var unorderedQuery: QueryInterfaceSelectQueryDefinition {
|
||||
var unorderedQuery: QueryInterfaceQuery {
|
||||
var query = self
|
||||
query.isReversed = false
|
||||
query.orderings = []
|
||||
@@ -168,7 +166,7 @@ struct QueryInterfaceSelectQueryDefinition {
|
||||
}
|
||||
}
|
||||
|
||||
extension QueryInterfaceSelectQueryDefinition : Request {
|
||||
extension QueryInterfaceQuery {
|
||||
func prepare(_ db: Database) throws -> (SelectStatement, RowAdapter?) {
|
||||
var arguments: StatementArguments? = StatementArguments()
|
||||
let sql = try self.sql(db, &arguments)
|
||||
@@ -178,7 +176,8 @@ extension QueryInterfaceSelectQueryDefinition : Request {
|
||||
}
|
||||
|
||||
func fetchCount(_ db: Database) throws -> Int {
|
||||
return try Int.fetchOne(db, countQuery)!
|
||||
let (statement, adapter) = try countQuery.prepare(db)
|
||||
return try Int.fetchOne(statement, adapter: adapter)!
|
||||
}
|
||||
|
||||
/// The database region that the request looks into.
|
||||
@@ -217,7 +216,7 @@ extension QueryInterfaceSelectQueryDefinition : Request {
|
||||
return region.tableIntersection(canonicalTableName, rowIds: rowIds)
|
||||
}
|
||||
|
||||
private var countQuery: QueryInterfaceSelectQueryDefinition {
|
||||
private var countQuery: QueryInterfaceQuery {
|
||||
guard groupByExpressions.isEmpty && limit == nil else {
|
||||
// SELECT ... GROUP BY ...
|
||||
// SELECT ... LIMIT ...
|
||||
@@ -255,8 +254,8 @@ extension QueryInterfaceSelectQueryDefinition : Request {
|
||||
}
|
||||
|
||||
// SELECT COUNT(*) FROM (self)
|
||||
private var trivialCountQuery: QueryInterfaceSelectQueryDefinition {
|
||||
return QueryInterfaceSelectQueryDefinition(
|
||||
private var trivialCountQuery: QueryInterfaceQuery {
|
||||
return QueryInterfaceQuery(
|
||||
select: [SQLExpressionCount(AllColumns())],
|
||||
from: .query(query: unorderedQuery, alias: nil))
|
||||
}
|
||||
@@ -264,7 +263,7 @@ extension QueryInterfaceSelectQueryDefinition : Request {
|
||||
|
||||
indirect enum SQLSource {
|
||||
case table(name: String, alias: String?)
|
||||
case query(query: QueryInterfaceSelectQueryDefinition, alias: String?)
|
||||
case query(query: QueryInterfaceQuery, alias: String?)
|
||||
|
||||
func sourceSQL(_ db: Database, _ arguments: inout StatementArguments?) throws -> String {
|
||||
switch self {
|
||||
@@ -2,14 +2,14 @@
|
||||
///
|
||||
/// See https://github.com/groue/GRDB.swift#the-query-interface
|
||||
public struct QueryInterfaceRequest<T> {
|
||||
let query: QueryInterfaceSelectQueryDefinition
|
||||
let query: QueryInterfaceQuery
|
||||
|
||||
init(query: QueryInterfaceSelectQueryDefinition) {
|
||||
init(query: QueryInterfaceQuery) {
|
||||
self.query = query
|
||||
}
|
||||
}
|
||||
|
||||
extension QueryInterfaceRequest : TypedRequest {
|
||||
extension QueryInterfaceRequest : FetchRequest {
|
||||
public typealias RowDecoder = T
|
||||
|
||||
/// A tuple that contains a prepared statement that is ready to be
|
||||
@@ -394,7 +394,10 @@ extension TableMapping {
|
||||
/// all requests by the `TableMapping.databaseSelection` property, or
|
||||
/// for individual requests with the `TableMapping.select` method.
|
||||
public static func all() -> QueryInterfaceRequest<Self> {
|
||||
return QueryInterfaceRequest(query: QueryInterfaceSelectQueryDefinition(select: databaseSelection, from: .table(name: databaseTableName, alias: nil)))
|
||||
let query = QueryInterfaceQuery(
|
||||
select: databaseSelection,
|
||||
from: .table(name: databaseTableName, alias: nil))
|
||||
return QueryInterfaceRequest(query: query)
|
||||
}
|
||||
|
||||
/// Creates a QueryInterfaceRequest which fetches no record.
|
||||
|
||||
@@ -47,7 +47,7 @@ public final class FetchedRecordsController<Record: RowConvertible> {
|
||||
{
|
||||
try self.init(
|
||||
databaseWriter,
|
||||
request: SQLRequest(sql, arguments: arguments, adapter: adapter).asRequest(of: Record.self),
|
||||
request: SQLRequest<Record>(sql, arguments: arguments, adapter: adapter),
|
||||
queue: queue,
|
||||
isSameRecord: isSameRecord)
|
||||
}
|
||||
@@ -79,7 +79,7 @@ public final class FetchedRecordsController<Record: RowConvertible> {
|
||||
request: Request,
|
||||
queue: DispatchQueue = .main,
|
||||
isSameRecord: ((Record, Record) -> Bool)? = nil) throws
|
||||
where Request: TypedRequest, Request.RowDecoder == Record
|
||||
where Request: FetchRequest, Request.RowDecoder == Record
|
||||
{
|
||||
let itemsAreIdenticalFactory: ItemComparatorFactory<Record>
|
||||
if let isSameRecord = isSameRecord {
|
||||
@@ -100,12 +100,14 @@ public final class FetchedRecordsController<Record: RowConvertible> {
|
||||
request: Request,
|
||||
queue: DispatchQueue,
|
||||
itemsAreIdenticalFactory: @escaping ItemComparatorFactory<Record>) throws
|
||||
where Request: TypedRequest, Request.RowDecoder == Record
|
||||
where Request: FetchRequest, Request.RowDecoder == Record
|
||||
{
|
||||
self.itemsAreIdenticalFactory = itemsAreIdenticalFactory
|
||||
self.request = request
|
||||
self.request = ItemRequest(request)
|
||||
(self.region, self.itemsAreIdentical) = try databaseWriter.unsafeRead { db in
|
||||
try FetchedRecordsController.fetchRegionAndComparator(db, request: request, itemsAreIdenticalFactory: itemsAreIdenticalFactory)
|
||||
let region = try request.fetchedRegion(db)
|
||||
let itemsAreIdentical = try itemsAreIdenticalFactory(db)
|
||||
return (region, itemsAreIdentical)
|
||||
}
|
||||
self.databaseWriter = databaseWriter
|
||||
self.queue = queue
|
||||
@@ -130,7 +132,7 @@ public final class FetchedRecordsController<Record: RowConvertible> {
|
||||
// observer is added on the same serialized queue as transaction
|
||||
// callbacks.
|
||||
try databaseWriter.write { db in
|
||||
let initialItems = try Item<Record>.fetchAll(db, request)
|
||||
let initialItems = try request.fetchAll(db)
|
||||
fetchedItems = initialItems
|
||||
if let fetchAndNotifyChanges = fetchAndNotifyChanges {
|
||||
let observer = FetchedRecordsObserver(region: self.region, fetchAndNotifyChanges: fetchAndNotifyChanges)
|
||||
@@ -160,10 +162,12 @@ public final class FetchedRecordsController<Record: RowConvertible> {
|
||||
///
|
||||
/// 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<Request>(_ request: Request) throws where Request: TypedRequest, Request.RowDecoder == Record {
|
||||
self.request = request
|
||||
public func setRequest<Request>(_ request: Request) throws where Request: FetchRequest, Request.RowDecoder == Record {
|
||||
self.request = ItemRequest(request)
|
||||
(self.region, self.itemsAreIdentical) = try databaseWriter.unsafeRead { db in
|
||||
try FetchedRecordsController.fetchRegionAndComparator(db, request: request, itemsAreIdenticalFactory: itemsAreIdenticalFactory)
|
||||
let region = try request.fetchedRegion(db)
|
||||
let itemsAreIdentical = try itemsAreIdenticalFactory(db)
|
||||
return (region, itemsAreIdentical)
|
||||
}
|
||||
|
||||
// No observer: don't look for changes
|
||||
@@ -193,7 +197,7 @@ public final class FetchedRecordsController<Record: RowConvertible> {
|
||||
/// 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).asRequest(of: Record.self))
|
||||
try setRequest(SQLRequest(sql, arguments: arguments, adapter: adapter))
|
||||
}
|
||||
|
||||
/// Registers changes notification callbacks.
|
||||
@@ -376,7 +380,8 @@ public final class FetchedRecordsController<Record: RowConvertible> {
|
||||
private let itemsAreIdenticalFactory: ItemComparatorFactory<Record>
|
||||
|
||||
/// The request
|
||||
fileprivate var request: Request
|
||||
fileprivate typealias ItemRequest = AnyFetchRequest<Item<Record>>
|
||||
fileprivate var request: ItemRequest
|
||||
|
||||
/// The observed database region
|
||||
private var region : DatabaseRegion
|
||||
@@ -386,17 +391,6 @@ public final class FetchedRecordsController<Record: RowConvertible> {
|
||||
|
||||
/// The eventual error handler
|
||||
fileprivate var errorHandler: ((FetchedRecordsController<Record>, Error) -> ())?
|
||||
|
||||
private static func fetchRegionAndComparator(
|
||||
_ db: Database,
|
||||
request: Request,
|
||||
itemsAreIdenticalFactory: ItemComparatorFactory<Record>) throws
|
||||
-> (DatabaseRegion, ItemComparator<Record>)
|
||||
{
|
||||
let region = try request.fetchedRegion(db)
|
||||
let itemsAreIdentical = try itemsAreIdenticalFactory(db)
|
||||
return (region, itemsAreIdentical)
|
||||
}
|
||||
}
|
||||
|
||||
extension FetchedRecordsController where Record: TableMapping {
|
||||
@@ -441,7 +435,7 @@ extension FetchedRecordsController where Record: TableMapping {
|
||||
{
|
||||
try self.init(
|
||||
databaseWriter,
|
||||
request: SQLRequest(sql, arguments: arguments, adapter: adapter).asRequest(of: Record.self),
|
||||
request: SQLRequest(sql, arguments: arguments, adapter: adapter),
|
||||
queue: queue)
|
||||
}
|
||||
|
||||
@@ -475,7 +469,7 @@ extension FetchedRecordsController where Record: TableMapping {
|
||||
_ databaseWriter: DatabaseWriter,
|
||||
request: Request,
|
||||
queue: DispatchQueue = .main) throws
|
||||
where Request: TypedRequest, Request.RowDecoder == Record
|
||||
where Request: FetchRequest, Request.RowDecoder == Record
|
||||
{
|
||||
// Builds a function that returns true if and only if two items
|
||||
// have the same primary key and primary keys contain at least one
|
||||
@@ -620,7 +614,7 @@ private func makeFetchFunction<Record, T>(
|
||||
do {
|
||||
try databaseWriter.readFromCurrentState { db in
|
||||
result = Result { try (
|
||||
fetchedItems: Item<Record>.fetchAll(db, request),
|
||||
fetchedItems: request.fetchAll(db),
|
||||
fetchedAlongside: fetchAlongside(db)) }
|
||||
semaphore.signal()
|
||||
}
|
||||
|
||||
@@ -125,61 +125,6 @@ extension RowConvertible {
|
||||
}
|
||||
}
|
||||
|
||||
extension RowConvertible {
|
||||
|
||||
// MARK: Fetching From Request
|
||||
|
||||
/// Returns a cursor over records fetched from a fetch request.
|
||||
///
|
||||
/// let nameColumn = Column("firstName")
|
||||
/// let request = Player.order(nameColumn)
|
||||
/// let identities = try Identity.fetchCursor(db, request) // Cursor of Identity
|
||||
/// while let identity = try identities.next() { // Identity
|
||||
/// ...
|
||||
/// }
|
||||
///
|
||||
/// If the database is modified during the cursor iteration, the remaining
|
||||
/// elements are undefined.
|
||||
///
|
||||
/// The cursor must be iterated in a protected dispath queue.
|
||||
///
|
||||
/// - parameters:
|
||||
/// - db: A database connection.
|
||||
/// - request: A fetch request.
|
||||
/// - returns: A cursor over fetched records.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public static func fetchCursor(_ db: Database, _ request: Request) throws -> RecordCursor<Self> {
|
||||
let (statement, adapter) = try request.prepare(db)
|
||||
return try fetchCursor(statement, adapter: adapter)
|
||||
}
|
||||
|
||||
/// Returns an array of records fetched from a fetch request.
|
||||
///
|
||||
/// let nameColumn = Column("name")
|
||||
/// let request = Player.order(nameColumn)
|
||||
/// let identities = try Identity.fetchAll(db, request) // [Identity]
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public static func fetchAll(_ db: Database, _ request: Request) throws -> [Self] {
|
||||
let (statement, adapter) = try request.prepare(db)
|
||||
return try fetchAll(statement, adapter: adapter)
|
||||
}
|
||||
|
||||
/// Returns a single record fetched from a fetch request.
|
||||
///
|
||||
/// let nameColumn = Column("name")
|
||||
/// let request = Player.order(nameColumn)
|
||||
/// let identity = try Identity.fetchOne(db, request) // Identity?
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public static func fetchOne(_ db: Database, _ request: Request) throws -> Self? {
|
||||
let (statement, adapter) = try request.prepare(db)
|
||||
return try fetchOne(statement, adapter: adapter)
|
||||
}
|
||||
}
|
||||
|
||||
extension RowConvertible {
|
||||
|
||||
// MARK: Fetching From SQL
|
||||
@@ -204,7 +149,7 @@ extension RowConvertible {
|
||||
/// - returns: A cursor over fetched records.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public static func fetchCursor(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> RecordCursor<Self> {
|
||||
return try fetchCursor(db, SQLRequest(sql, arguments: arguments, adapter: adapter))
|
||||
return try SQLRequest<Self>(sql, arguments: arguments, adapter: adapter).fetchCursor(db)
|
||||
}
|
||||
|
||||
/// Returns an array of records fetched from an SQL query.
|
||||
@@ -219,7 +164,7 @@ extension RowConvertible {
|
||||
/// - returns: An array of records.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public static func fetchAll(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> [Self] {
|
||||
return try fetchAll(db, SQLRequest(sql, arguments: arguments, adapter: adapter))
|
||||
return try SQLRequest<Self>(sql, arguments: arguments, adapter: adapter).fetchAll(db)
|
||||
}
|
||||
|
||||
/// Returns a single record fetched from an SQL query.
|
||||
@@ -234,6 +179,59 @@ extension RowConvertible {
|
||||
/// - returns: An optional record.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public static func fetchOne(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> Self? {
|
||||
return try fetchOne(db, SQLRequest(sql, arguments: arguments, adapter: adapter))
|
||||
return try SQLRequest<Self>(sql, arguments: arguments, adapter: adapter).fetchOne(db)
|
||||
}
|
||||
}
|
||||
|
||||
extension FetchRequest where RowDecoder: RowConvertible {
|
||||
|
||||
// MARK: Fetching Record and RowConvertible
|
||||
|
||||
/// A cursor over fetched records.
|
||||
///
|
||||
/// let request: ... // Some TypedRequest that fetches Player
|
||||
/// let players = try request.fetchCursor(db) // Cursor of Player
|
||||
/// while let player = try players.next() { // Player
|
||||
/// ...
|
||||
/// }
|
||||
///
|
||||
/// If the database is modified during the cursor iteration, the remaining
|
||||
/// elements are undefined.
|
||||
///
|
||||
/// The cursor must be iterated in a protected dispath queue.
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
/// - returns: A cursor over fetched records.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public func fetchCursor(_ db: Database) throws -> RecordCursor<RowDecoder> {
|
||||
let (statement, adapter) = try prepare(db)
|
||||
return try RowDecoder.fetchCursor(statement, adapter: adapter)
|
||||
}
|
||||
|
||||
/// An array of fetched records.
|
||||
///
|
||||
/// let request: ... // Some TypedRequest that fetches Player
|
||||
/// let players = try request.fetchAll(db) // [Player]
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
/// - returns: An array of records.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public func fetchAll(_ db: Database) throws -> [RowDecoder] {
|
||||
let (statement, adapter) = try prepare(db)
|
||||
return try RowDecoder.fetchAll(statement, adapter: adapter)
|
||||
}
|
||||
|
||||
/// The first fetched record.
|
||||
///
|
||||
/// let request: ... // Some TypedRequest that fetches Player
|
||||
/// let player = try request.fetchOne(db) // Player?
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
/// - returns: An optional record.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public func fetchOne(_ db: Database) throws -> RowDecoder? {
|
||||
let (statement, adapter) = try prepare(db)
|
||||
return try RowDecoder.fetchOne(statement, adapter: adapter)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
560FC5311CB003810014AA8E /* TableMapping.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560D92461C672C4B00F4F92B /* TableMapping.swift */; };
|
||||
560FC5321CB003810014AA8E /* DatabasePool.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560A37A31C8F625000949E71 /* DatabasePool.swift */; };
|
||||
560FC5331CB003810014AA8E /* Migration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B7F4391BEB42D500E39BBF /* Migration.swift */; };
|
||||
560FC5341CB003810014AA8E /* QueryInterfaceSelectQueryDefinition.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5605F18C1C6B1A8700235C62 /* QueryInterfaceSelectQueryDefinition.swift */; };
|
||||
560FC5341CB003810014AA8E /* QueryInterfaceQuery.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5605F18C1C6B1A8700235C62 /* QueryInterfaceQuery.swift */; };
|
||||
560FC5351CB003810014AA8E /* Statement.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238781B9C75030082EB20 /* Statement.swift */; };
|
||||
560FC5361CB003810014AA8E /* DatabaseMigrator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238921B9C750B0082EB20 /* DatabaseMigrator.swift */; };
|
||||
560FC5371CB003810014AA8E /* DatabaseSchemaCache.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5695311E1C907A8C00CF1A2B /* DatabaseSchemaCache.swift */; };
|
||||
@@ -181,8 +181,8 @@
|
||||
5634B1091CF9B970005360B9 /* TransactionObserverSavepointsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5634B1061CF9B970005360B9 /* TransactionObserverSavepointsTests.swift */; };
|
||||
5634B10B1CF9B970005360B9 /* TransactionObserverSavepointsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5634B1061CF9B970005360B9 /* TransactionObserverSavepointsTests.swift */; };
|
||||
5634B10C1CF9B970005360B9 /* TransactionObserverSavepointsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5634B1061CF9B970005360B9 /* TransactionObserverSavepointsTests.swift */; };
|
||||
5636E9BD1D22574100B9B05F /* Request.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5636E9BB1D22574100B9B05F /* Request.swift */; };
|
||||
5636E9C01D22574100B9B05F /* Request.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5636E9BB1D22574100B9B05F /* Request.swift */; };
|
||||
5636E9BD1D22574100B9B05F /* FetchRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5636E9BB1D22574100B9B05F /* FetchRequest.swift */; };
|
||||
5636E9C01D22574100B9B05F /* FetchRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5636E9BB1D22574100B9B05F /* FetchRequest.swift */; };
|
||||
564448841EF56B1B00DD2861 /* DatabaseAfterNextTransactionCommitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564448821EF56B1B00DD2861 /* DatabaseAfterNextTransactionCommitTests.swift */; };
|
||||
564448851EF56B1B00DD2861 /* DatabaseAfterNextTransactionCommitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564448821EF56B1B00DD2861 /* DatabaseAfterNextTransactionCommitTests.swift */; };
|
||||
564448881EF56B1B00DD2861 /* DatabaseAfterNextTransactionCommitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564448821EF56B1B00DD2861 /* DatabaseAfterNextTransactionCommitTests.swift */; };
|
||||
@@ -350,10 +350,10 @@
|
||||
5672DE6C1CDB751D0022BA81 /* DatabasePoolBackupTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5672DE661CDB751D0022BA81 /* DatabasePoolBackupTests.swift */; };
|
||||
567404891CEF84C8003ED5CC /* RowAdapter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 567404871CEF84C8003ED5CC /* RowAdapter.swift */; };
|
||||
5674048B1CEF84C8003ED5CC /* RowAdapter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 567404871CEF84C8003ED5CC /* RowAdapter.swift */; };
|
||||
56741EA91E66A8B3003E422D /* RequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56741EA71E66A8B3003E422D /* RequestTests.swift */; };
|
||||
56741EAA1E66A8B3003E422D /* RequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56741EA71E66A8B3003E422D /* RequestTests.swift */; };
|
||||
56741EAD1E66A8B3003E422D /* RequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56741EA71E66A8B3003E422D /* RequestTests.swift */; };
|
||||
56741EAE1E66A8B3003E422D /* RequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56741EA71E66A8B3003E422D /* RequestTests.swift */; };
|
||||
56741EA91E66A8B3003E422D /* FetchRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56741EA71E66A8B3003E422D /* FetchRequestTests.swift */; };
|
||||
56741EAA1E66A8B3003E422D /* FetchRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56741EA71E66A8B3003E422D /* FetchRequestTests.swift */; };
|
||||
56741EAD1E66A8B3003E422D /* FetchRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56741EA71E66A8B3003E422D /* FetchRequestTests.swift */; };
|
||||
56741EAE1E66A8B3003E422D /* FetchRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56741EA71E66A8B3003E422D /* FetchRequestTests.swift */; };
|
||||
5674A6E71F307F0E0095F066 /* DatabaseValueConvertible+Decodable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5674A6E31F307F0E0095F066 /* DatabaseValueConvertible+Decodable.swift */; };
|
||||
5674A6EA1F307F0E0095F066 /* DatabaseValueConvertible+Decodable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5674A6E31F307F0E0095F066 /* DatabaseValueConvertible+Decodable.swift */; };
|
||||
5674A6EE1F307F0E0095F066 /* DatabaseValueConvertible+Encodable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5674A6E21F307F0E0095F066 /* DatabaseValueConvertible+Encodable.swift */; };
|
||||
@@ -482,6 +482,8 @@
|
||||
5698AD251DABAEFA0056AF8C /* FTS5WrapperTokenizer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698AD201DABAEFA0056AF8C /* FTS5WrapperTokenizer.swift */; };
|
||||
5698AD361DABAF4A0056AF8C /* FTS5CustomTokenizer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698AD341DABAF4A0056AF8C /* FTS5CustomTokenizer.swift */; };
|
||||
5698AD391DABAF4A0056AF8C /* FTS5CustomTokenizer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698AD341DABAF4A0056AF8C /* FTS5CustomTokenizer.swift */; };
|
||||
569A98FC2039B72D008D7DBF /* Fixits-3.0.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569A98FA2039B72C008D7DBF /* Fixits-3.0.swift */; };
|
||||
569A98FD2039B72D008D7DBF /* Fixits-3.0.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569A98FA2039B72C008D7DBF /* Fixits-3.0.swift */; };
|
||||
569B7FA8201C904C0069DE70 /* Swift4.1.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569B7FA6201C904C0069DE70 /* Swift4.1.swift */; };
|
||||
569B7FA9201C904C0069DE70 /* Swift4.1.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569B7FA6201C904C0069DE70 /* Swift4.1.swift */; };
|
||||
569C1EB31CF07DDD0042627B /* SchedulingWatchdogTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569C1EB11CF07DDD0042627B /* SchedulingWatchdogTests.swift */; };
|
||||
@@ -529,7 +531,7 @@
|
||||
56AFCA061CB1A8BB00F48B96 /* Configuration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238701B9C75030082EB20 /* Configuration.swift */; };
|
||||
56AFCA071CB1A8BB00F48B96 /* DatabasePool.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560A37A31C8F625000949E71 /* DatabasePool.swift */; };
|
||||
56AFCA081CB1A8BB00F48B96 /* Statement.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238781B9C75030082EB20 /* Statement.swift */; };
|
||||
56AFCA091CB1A8BB00F48B96 /* QueryInterfaceSelectQueryDefinition.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5605F18C1C6B1A8700235C62 /* QueryInterfaceSelectQueryDefinition.swift */; };
|
||||
56AFCA091CB1A8BB00F48B96 /* QueryInterfaceQuery.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5605F18C1C6B1A8700235C62 /* QueryInterfaceQuery.swift */; };
|
||||
56AFCA0A1CB1A8BB00F48B96 /* Migration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B7F4391BEB42D500E39BBF /* Migration.swift */; };
|
||||
56AFCA0B1CB1A8BB00F48B96 /* Row.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238761B9C75030082EB20 /* Row.swift */; };
|
||||
56AFCA0C1CB1A8BB00F48B96 /* DatabaseSchemaCache.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5695311E1C907A8C00CF1A2B /* DatabaseSchemaCache.swift */; };
|
||||
@@ -839,7 +841,7 @@
|
||||
5605F1581C672E4000235C62 /* StandardLibrary.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StandardLibrary.swift; sourceTree = "<group>"; };
|
||||
5605F1861C69111300235C62 /* DatabaseRegionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseRegionTests.swift; sourceTree = "<group>"; };
|
||||
5605F1891C6B1A8700235C62 /* SQLCollatedExpression.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SQLCollatedExpression.swift; sourceTree = "<group>"; };
|
||||
5605F18C1C6B1A8700235C62 /* QueryInterfaceSelectQueryDefinition.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QueryInterfaceSelectQueryDefinition.swift; sourceTree = "<group>"; };
|
||||
5605F18C1C6B1A8700235C62 /* QueryInterfaceQuery.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QueryInterfaceQuery.swift; sourceTree = "<group>"; };
|
||||
5607EFD21BB8254800605DE3 /* TransactionObserverTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TransactionObserverTests.swift; sourceTree = "<group>"; };
|
||||
560A37A31C8F625000949E71 /* DatabasePool.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabasePool.swift; sourceTree = "<group>"; };
|
||||
560A37A61C8FF6E500949E71 /* SerializedDatabase.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SerializedDatabase.swift; sourceTree = "<group>"; };
|
||||
@@ -879,7 +881,7 @@
|
||||
563363CF1C943D13000BE133 /* DatabasePoolReleaseMemoryTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabasePoolReleaseMemoryTests.swift; sourceTree = "<group>"; };
|
||||
563363D41C94484E000BE133 /* DatabaseQueueReleaseMemoryTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseQueueReleaseMemoryTests.swift; sourceTree = "<group>"; };
|
||||
5634B1061CF9B970005360B9 /* TransactionObserverSavepointsTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TransactionObserverSavepointsTests.swift; sourceTree = "<group>"; };
|
||||
5636E9BB1D22574100B9B05F /* Request.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Request.swift; sourceTree = "<group>"; };
|
||||
5636E9BB1D22574100B9B05F /* FetchRequest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FetchRequest.swift; sourceTree = "<group>"; };
|
||||
564448821EF56B1B00DD2861 /* DatabaseAfterNextTransactionCommitTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseAfterNextTransactionCommitTests.swift; sourceTree = "<group>"; };
|
||||
564A50C61BFF4B7F00B3A3A2 /* DatabaseCollationTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseCollationTests.swift; sourceTree = "<group>"; };
|
||||
564E73EB203DA29B000C443C /* JoinSupportTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JoinSupportTests.swift; sourceTree = "<group>"; };
|
||||
@@ -926,7 +928,7 @@
|
||||
5672DE581CDB72520022BA81 /* DatabaseQueueBackupTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseQueueBackupTests.swift; sourceTree = "<group>"; };
|
||||
5672DE661CDB751D0022BA81 /* DatabasePoolBackupTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabasePoolBackupTests.swift; sourceTree = "<group>"; };
|
||||
567404871CEF84C8003ED5CC /* RowAdapter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RowAdapter.swift; sourceTree = "<group>"; };
|
||||
56741EA71E66A8B3003E422D /* RequestTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RequestTests.swift; sourceTree = "<group>"; };
|
||||
56741EA71E66A8B3003E422D /* FetchRequestTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FetchRequestTests.swift; sourceTree = "<group>"; };
|
||||
5674A6E21F307F0E0095F066 /* DatabaseValueConvertible+Encodable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DatabaseValueConvertible+Encodable.swift"; sourceTree = "<group>"; };
|
||||
5674A6E31F307F0E0095F066 /* DatabaseValueConvertible+Decodable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DatabaseValueConvertible+Decodable.swift"; sourceTree = "<group>"; };
|
||||
5674A6F21F307F600095F066 /* RowConvertible+Decodable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "RowConvertible+Decodable.swift"; sourceTree = "<group>"; };
|
||||
@@ -976,6 +978,7 @@
|
||||
5698AD151DAAD16F0056AF8C /* FTS5Tokenizer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS5Tokenizer.swift; sourceTree = "<group>"; };
|
||||
5698AD201DABAEFA0056AF8C /* FTS5WrapperTokenizer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS5WrapperTokenizer.swift; sourceTree = "<group>"; };
|
||||
5698AD341DABAF4A0056AF8C /* FTS5CustomTokenizer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS5CustomTokenizer.swift; sourceTree = "<group>"; };
|
||||
569A98FA2039B72C008D7DBF /* Fixits-3.0.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Fixits-3.0.swift"; sourceTree = "<group>"; };
|
||||
569B7FA6201C904C0069DE70 /* Swift4.1.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Swift4.1.swift; sourceTree = "<group>"; };
|
||||
569C1EB11CF07DDD0042627B /* SchedulingWatchdogTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SchedulingWatchdogTests.swift; sourceTree = "<group>"; };
|
||||
569EF0E8200D387000A9FA45 /* DatabaseRegion.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseRegion.swift; sourceTree = "<group>"; };
|
||||
@@ -1333,8 +1336,8 @@
|
||||
56CEB5401EAA359A00BFAF62 /* Column.swift */,
|
||||
56CEB5101EAA324B00BFAF62 /* FTS3+QueryInterfaceRequest.swift */,
|
||||
56CEB5181EAA328900BFAF62 /* FTS5+QueryInterface.swift */,
|
||||
5605F18C1C6B1A8700235C62 /* QueryInterfaceQuery.swift */,
|
||||
56300B6F1C53F592005A543B /* QueryInterfaceRequest.swift */,
|
||||
5605F18C1C6B1A8700235C62 /* QueryInterfaceSelectQueryDefinition.swift */,
|
||||
5605F1891C6B1A8700235C62 /* SQLCollatedExpression.swift */,
|
||||
566475991D97D8A000FF74B8 /* SQLCollection.swift */,
|
||||
56CEB5411EAA359A00BFAF62 /* SQLExpressible.swift */,
|
||||
@@ -1467,10 +1470,10 @@
|
||||
56A238181B9C74A90082EB20 /* DatabaseValueTests.swift */,
|
||||
562756421E963AAC0035B653 /* DatabaseWriterTests.swift */,
|
||||
56A5EF0E1EF7F20B00F03071 /* ForeignKeyInfoTests.swift */,
|
||||
56741EA71E66A8B3003E422D /* FetchRequestTests.swift */,
|
||||
567A80521D41350C00C7DCEC /* IndexInfoTests.swift */,
|
||||
56D5075D1F6BAE8600AE1C5B /* PrimaryKeyInfoTests.swift */,
|
||||
565EFAED1D0436CE00A8FA9D /* NumericOverflowTests.swift */,
|
||||
56741EA71E66A8B3003E422D /* RequestTests.swift */,
|
||||
56F3E7481E66F83A00BF0F01 /* ResultCodeTests.swift */,
|
||||
56A2381D1B9C74A90082EB20 /* Row */,
|
||||
569C1EB11CF07DDD0042627B /* SchedulingWatchdogTests.swift */,
|
||||
@@ -1561,7 +1564,7 @@
|
||||
56A238751B9C75030082EB20 /* DatabaseValue.swift */,
|
||||
560D923E1C672C3E00F4F92B /* DatabaseValueConvertible.swift */,
|
||||
563363C31C942C37000BE133 /* DatabaseWriter.swift */,
|
||||
5636E9BB1D22574100B9B05F /* Request.swift */,
|
||||
5636E9BB1D22574100B9B05F /* FetchRequest.swift */,
|
||||
56A238761B9C75030082EB20 /* Row.swift */,
|
||||
567404871CEF84C8003ED5CC /* RowAdapter.swift */,
|
||||
56BB6EA81D3009B100A1CA52 /* SchedulingWatchdog.swift */,
|
||||
@@ -1610,6 +1613,7 @@
|
||||
56E06F051E859064008AE2A4 /* Fixits-0.102.0.swift */,
|
||||
56D121591ED34978001347D2 /* Fixits-0.109.0.swift */,
|
||||
56873BEB1F2CB400004D24B4 /* Fixits-1.2.swift */,
|
||||
569A98FA2039B72C008D7DBF /* Fixits-3.0.swift */,
|
||||
569B7FA6201C904C0069DE70 /* Swift4.1.swift */,
|
||||
);
|
||||
path = Legacy;
|
||||
@@ -1989,7 +1993,7 @@
|
||||
files = (
|
||||
56873BED1F2CB400004D24B4 /* Fixits-1.2.swift in Sources */,
|
||||
56BF6D3E1DEF47DA006039A3 /* Fixits-Swift2.swift in Sources */,
|
||||
5636E9BD1D22574100B9B05F /* Request.swift in Sources */,
|
||||
5636E9BD1D22574100B9B05F /* FetchRequest.swift in Sources */,
|
||||
56BB6EAA1D3009B100A1CA52 /* SchedulingWatchdog.swift in Sources */,
|
||||
566B910A1FA4C3970012D5B0 /* Database+Statements.swift in Sources */,
|
||||
566B91241FA4CF810012D5B0 /* Database+Schema.swift in Sources */,
|
||||
@@ -2047,7 +2051,7 @@
|
||||
5674A6F11F307F0E0095F066 /* DatabaseValueConvertible+Encodable.swift in Sources */,
|
||||
560FC5321CB003810014AA8E /* DatabasePool.swift in Sources */,
|
||||
560FC5331CB003810014AA8E /* Migration.swift in Sources */,
|
||||
560FC5341CB003810014AA8E /* QueryInterfaceSelectQueryDefinition.swift in Sources */,
|
||||
560FC5341CB003810014AA8E /* QueryInterfaceQuery.swift in Sources */,
|
||||
566B912C1FA4D0CC0012D5B0 /* StatementAuthorizer.swift in Sources */,
|
||||
560FC5351CB003810014AA8E /* Statement.swift in Sources */,
|
||||
5690C3411D23E82A00E59934 /* Data.swift in Sources */,
|
||||
@@ -2068,6 +2072,7 @@
|
||||
566AD8B31D5318F4002EC1A8 /* TableDefinition.swift in Sources */,
|
||||
5698AD221DABAEFA0056AF8C /* FTS5WrapperTokenizer.swift in Sources */,
|
||||
560FC53C1CB003810014AA8E /* DatabaseQueue.swift in Sources */,
|
||||
569A98FC2039B72D008D7DBF /* Fixits-3.0.swift in Sources */,
|
||||
560FC53D1CB003810014AA8E /* NSNumber.swift in Sources */,
|
||||
560FC53F1CB003810014AA8E /* Row.swift in Sources */,
|
||||
560FC5401CB003810014AA8E /* StandardLibrary.swift in Sources */,
|
||||
@@ -2160,7 +2165,7 @@
|
||||
560FC5811CB00B880014AA8E /* RecordCopyTests.swift in Sources */,
|
||||
560FC5821CB00B880014AA8E /* RawRepresentable+DatabaseValueConvertibleTests.swift in Sources */,
|
||||
567E55ED1D2BDD3D00CC6F79 /* EncryptionTests.swift in Sources */,
|
||||
56741EA91E66A8B3003E422D /* RequestTests.swift in Sources */,
|
||||
56741EA91E66A8B3003E422D /* FetchRequestTests.swift in Sources */,
|
||||
56176C641EACCCC7000F3F2B /* FTS5WrapperTokenizerTests.swift in Sources */,
|
||||
560FC5841CB00B880014AA8E /* PersistableTests.swift in Sources */,
|
||||
560FC5871CB00B880014AA8E /* RecordSubClassTests.swift in Sources */,
|
||||
@@ -2308,7 +2313,7 @@
|
||||
5657AB501D108BA9006283EF /* FoundationNSNumberTests.swift in Sources */,
|
||||
567156441CB16729007DC145 /* RecordSubClassTests.swift in Sources */,
|
||||
5690C3391D23E7D200E59934 /* FoundationDateTests.swift in Sources */,
|
||||
56741EAA1E66A8B3003E422D /* RequestTests.swift in Sources */,
|
||||
56741EAA1E66A8B3003E422D /* FetchRequestTests.swift in Sources */,
|
||||
56176C6A1EACCCC8000F3F2B /* FTS5WrapperTokenizerTests.swift in Sources */,
|
||||
567156461CB16729007DC145 /* TransactionObserverTests.swift in Sources */,
|
||||
567A80551D41350C00C7DCEC /* IndexInfoTests.swift in Sources */,
|
||||
@@ -2384,7 +2389,7 @@
|
||||
files = (
|
||||
56873BF01F2CB400004D24B4 /* Fixits-1.2.swift in Sources */,
|
||||
56BF6D411DEF47DA006039A3 /* Fixits-Swift2.swift in Sources */,
|
||||
5636E9C01D22574100B9B05F /* Request.swift in Sources */,
|
||||
5636E9C01D22574100B9B05F /* FetchRequest.swift in Sources */,
|
||||
56BB6EAD1D3009B100A1CA52 /* SchedulingWatchdog.swift in Sources */,
|
||||
566B910D1FA4C3970012D5B0 /* Database+Statements.swift in Sources */,
|
||||
566B91271FA4CF810012D5B0 /* Database+Schema.swift in Sources */,
|
||||
@@ -2442,7 +2447,7 @@
|
||||
5674A6EE1F307F0E0095F066 /* DatabaseValueConvertible+Encodable.swift in Sources */,
|
||||
56AFCA071CB1A8BB00F48B96 /* DatabasePool.swift in Sources */,
|
||||
56AFCA081CB1A8BB00F48B96 /* Statement.swift in Sources */,
|
||||
56AFCA091CB1A8BB00F48B96 /* QueryInterfaceSelectQueryDefinition.swift in Sources */,
|
||||
56AFCA091CB1A8BB00F48B96 /* QueryInterfaceQuery.swift in Sources */,
|
||||
566B912F1FA4D0CC0012D5B0 /* StatementAuthorizer.swift in Sources */,
|
||||
56AFCA0A1CB1A8BB00F48B96 /* Migration.swift in Sources */,
|
||||
5690C3441D23E82A00E59934 /* Data.swift in Sources */,
|
||||
@@ -2463,6 +2468,7 @@
|
||||
566AD8B61D5318F4002EC1A8 /* TableDefinition.swift in Sources */,
|
||||
5698AD251DABAEFA0056AF8C /* FTS5WrapperTokenizer.swift in Sources */,
|
||||
56AFCA121CB1A8BB00F48B96 /* NSNumber.swift in Sources */,
|
||||
569A98FD2039B72D008D7DBF /* Fixits-3.0.swift in Sources */,
|
||||
56AFCA141CB1A8BB00F48B96 /* StandardLibrary.swift in Sources */,
|
||||
56AFCA151CB1A8BB00F48B96 /* Persistable.swift in Sources */,
|
||||
56AFCA161CB1A8BB00F48B96 /* StatementColumnConvertible.swift in Sources */,
|
||||
@@ -2555,7 +2561,7 @@
|
||||
5698ACBB1DA6285E0056AF8C /* FTS3TokenizerTests.swift in Sources */,
|
||||
56AFCA561CB1AA9900F48B96 /* DatabasePoolConcurrencyTests.swift in Sources */,
|
||||
56AFCA571CB1AA9900F48B96 /* TransactionObserverTests.swift in Sources */,
|
||||
56741EAD1E66A8B3003E422D /* RequestTests.swift in Sources */,
|
||||
56741EAD1E66A8B3003E422D /* FetchRequestTests.swift in Sources */,
|
||||
56176C761EACCCCA000F3F2B /* FTS5WrapperTokenizerTests.swift in Sources */,
|
||||
5623935C1DEE013C00A6B01F /* FilterCursorTests.swift in Sources */,
|
||||
5698AC851DA380A20056AF8C /* VirtualTableModuleTests.swift in Sources */,
|
||||
@@ -2703,7 +2709,7 @@
|
||||
5698ACBC1DA6285E0056AF8C /* FTS3TokenizerTests.swift in Sources */,
|
||||
5657AB441D108BA9006283EF /* FoundationNSDataTests.swift in Sources */,
|
||||
5623935D1DEE013C00A6B01F /* FilterCursorTests.swift in Sources */,
|
||||
56741EAE1E66A8B3003E422D /* RequestTests.swift in Sources */,
|
||||
56741EAE1E66A8B3003E422D /* FetchRequestTests.swift in Sources */,
|
||||
56176C7C1EACCCCB000F3F2B /* FTS5WrapperTokenizerTests.swift in Sources */,
|
||||
5698AC861DA380A20056AF8C /* VirtualTableModuleTests.swift in Sources */,
|
||||
5698AC461DA2BED90056AF8C /* FTS3PatternTests.swift in Sources */,
|
||||
|
||||
@@ -41,8 +41,8 @@
|
||||
562EA82D1F17B2AC00FA528C /* CompilationProtocolTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 562EA8251F17B2AC00FA528C /* CompilationProtocolTests.swift */; };
|
||||
562EA8321F17B9EB00FA528C /* CompilationSubClassTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 562EA82E1F17B9EB00FA528C /* CompilationSubClassTests.swift */; };
|
||||
562EA8361F17B9EB00FA528C /* CompilationSubClassTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 562EA82E1F17B9EB00FA528C /* CompilationSubClassTests.swift */; };
|
||||
5636E9BE1D22574100B9B05F /* Request.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5636E9BB1D22574100B9B05F /* Request.swift */; };
|
||||
5636E9C11D22574100B9B05F /* Request.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5636E9BB1D22574100B9B05F /* Request.swift */; };
|
||||
5636E9BE1D22574100B9B05F /* FetchRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5636E9BB1D22574100B9B05F /* FetchRequest.swift */; };
|
||||
5636E9C11D22574100B9B05F /* FetchRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5636E9BB1D22574100B9B05F /* FetchRequest.swift */; };
|
||||
564448861EF56B1B00DD2861 /* DatabaseAfterNextTransactionCommitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564448821EF56B1B00DD2861 /* DatabaseAfterNextTransactionCommitTests.swift */; };
|
||||
5644488A1EF56B1B00DD2861 /* DatabaseAfterNextTransactionCommitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564448821EF56B1B00DD2861 /* DatabaseAfterNextTransactionCommitTests.swift */; };
|
||||
564E73F3203DA2AC000C443C /* JoinSupportTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564E73E7203DA278000C443C /* JoinSupportTests.swift */; };
|
||||
@@ -113,8 +113,8 @@
|
||||
566B91381FA4D3810012D5B0 /* TransactionObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 566B91321FA4D3810012D5B0 /* TransactionObserver.swift */; };
|
||||
5671FC221DA3CAC9003BF4FF /* FTS3TokenizerDescriptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5671FC1F1DA3CAC9003BF4FF /* FTS3TokenizerDescriptor.swift */; };
|
||||
5671FC251DA3CAC9003BF4FF /* FTS3TokenizerDescriptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5671FC1F1DA3CAC9003BF4FF /* FTS3TokenizerDescriptor.swift */; };
|
||||
56741EAB1E66A8B3003E422D /* RequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56741EA71E66A8B3003E422D /* RequestTests.swift */; };
|
||||
56741EAF1E66A8B3003E422D /* RequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56741EA71E66A8B3003E422D /* RequestTests.swift */; };
|
||||
56741EAB1E66A8B3003E422D /* FetchRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56741EA71E66A8B3003E422D /* FetchRequestTests.swift */; };
|
||||
56741EAF1E66A8B3003E422D /* FetchRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56741EA71E66A8B3003E422D /* FetchRequestTests.swift */; };
|
||||
5674A6E51F307F0E0095F066 /* DatabaseValueConvertible+Decodable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5674A6E31F307F0E0095F066 /* DatabaseValueConvertible+Decodable.swift */; };
|
||||
5674A6E61F307F0E0095F066 /* DatabaseValueConvertible+Decodable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5674A6E31F307F0E0095F066 /* DatabaseValueConvertible+Decodable.swift */; };
|
||||
5674A6EC1F307F0E0095F066 /* DatabaseValueConvertible+Encodable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5674A6E21F307F0E0095F066 /* DatabaseValueConvertible+Encodable.swift */; };
|
||||
@@ -189,6 +189,8 @@
|
||||
5698AD261DABAEFA0056AF8C /* FTS5WrapperTokenizer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698AD201DABAEFA0056AF8C /* FTS5WrapperTokenizer.swift */; };
|
||||
5698AD371DABAF4A0056AF8C /* FTS5CustomTokenizer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698AD341DABAF4A0056AF8C /* FTS5CustomTokenizer.swift */; };
|
||||
5698AD3A1DABAF4A0056AF8C /* FTS5CustomTokenizer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698AD341DABAF4A0056AF8C /* FTS5CustomTokenizer.swift */; };
|
||||
569A98F82039B716008D7DBF /* Fixits-3.0.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569A98F62039B716008D7DBF /* Fixits-3.0.swift */; };
|
||||
569A98F92039B716008D7DBF /* Fixits-3.0.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569A98F62039B716008D7DBF /* Fixits-3.0.swift */; };
|
||||
569B7FA4201C90430069DE70 /* Swift4.1.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569B7FA2201C90430069DE70 /* Swift4.1.swift */; };
|
||||
569B7FA5201C90430069DE70 /* Swift4.1.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569B7FA2201C90430069DE70 /* Swift4.1.swift */; };
|
||||
569EF0E6200D37FD00A9FA45 /* DatabaseRegion.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569EF0E5200D37FC00A9FA45 /* DatabaseRegion.swift */; };
|
||||
@@ -313,7 +315,7 @@
|
||||
F3BA80281CFB2891003DC1BA /* StandardLibrary.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5605F1581C672E4000235C62 /* StandardLibrary.swift */; };
|
||||
F3BA802B1CFB289B003DC1BA /* QueryInterfaceRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56300B6F1C53F592005A543B /* QueryInterfaceRequest.swift */; };
|
||||
F3BA802C1CFB289B003DC1BA /* SQLCollatedExpression.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5605F1891C6B1A8700235C62 /* SQLCollatedExpression.swift */; };
|
||||
F3BA802F1CFB289B003DC1BA /* QueryInterfaceSelectQueryDefinition.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5605F18C1C6B1A8700235C62 /* QueryInterfaceSelectQueryDefinition.swift */; };
|
||||
F3BA802F1CFB289B003DC1BA /* QueryInterfaceQuery.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5605F18C1C6B1A8700235C62 /* QueryInterfaceQuery.swift */; };
|
||||
F3BA80301CFB289F003DC1BA /* DatabaseMigrator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238921B9C750B0082EB20 /* DatabaseMigrator.swift */; };
|
||||
F3BA80311CFB289F003DC1BA /* Migration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B7F4391BEB42D500E39BBF /* Migration.swift */; };
|
||||
F3BA80321CFB28A4003DC1BA /* FetchedRecordsController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 31A7787C1C6A4DD600F507F6 /* FetchedRecordsController.swift */; };
|
||||
@@ -357,7 +359,7 @@
|
||||
F3BA80841CFB2E67003DC1BA /* StandardLibrary.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5605F1581C672E4000235C62 /* StandardLibrary.swift */; };
|
||||
F3BA80871CFB2E70003DC1BA /* QueryInterfaceRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56300B6F1C53F592005A543B /* QueryInterfaceRequest.swift */; };
|
||||
F3BA80881CFB2E70003DC1BA /* SQLCollatedExpression.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5605F1891C6B1A8700235C62 /* SQLCollatedExpression.swift */; };
|
||||
F3BA808B1CFB2E70003DC1BA /* QueryInterfaceSelectQueryDefinition.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5605F18C1C6B1A8700235C62 /* QueryInterfaceSelectQueryDefinition.swift */; };
|
||||
F3BA808B1CFB2E70003DC1BA /* QueryInterfaceQuery.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5605F18C1C6B1A8700235C62 /* QueryInterfaceQuery.swift */; };
|
||||
F3BA808C1CFB2E75003DC1BA /* DatabaseMigrator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238921B9C750B0082EB20 /* DatabaseMigrator.swift */; };
|
||||
F3BA808D1CFB2E75003DC1BA /* Migration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B7F4391BEB42D500E39BBF /* Migration.swift */; };
|
||||
F3BA808E1CFB2E7A003DC1BA /* FetchedRecordsController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 31A7787C1C6A4DD600F507F6 /* FetchedRecordsController.swift */; };
|
||||
@@ -541,7 +543,7 @@
|
||||
5605F1581C672E4000235C62 /* StandardLibrary.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StandardLibrary.swift; sourceTree = "<group>"; };
|
||||
5605F1861C69111300235C62 /* DatabaseRegionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseRegionTests.swift; sourceTree = "<group>"; };
|
||||
5605F1891C6B1A8700235C62 /* SQLCollatedExpression.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SQLCollatedExpression.swift; sourceTree = "<group>"; };
|
||||
5605F18C1C6B1A8700235C62 /* QueryInterfaceSelectQueryDefinition.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QueryInterfaceSelectQueryDefinition.swift; sourceTree = "<group>"; };
|
||||
5605F18C1C6B1A8700235C62 /* QueryInterfaceQuery.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QueryInterfaceQuery.swift; sourceTree = "<group>"; };
|
||||
5607EFD21BB8254800605DE3 /* TransactionObserverTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TransactionObserverTests.swift; sourceTree = "<group>"; };
|
||||
560A37A31C8F625000949E71 /* DatabasePool.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabasePool.swift; sourceTree = "<group>"; };
|
||||
560A37A61C8FF6E500949E71 /* SerializedDatabase.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SerializedDatabase.swift; sourceTree = "<group>"; };
|
||||
@@ -578,7 +580,7 @@
|
||||
563363CF1C943D13000BE133 /* DatabasePoolReleaseMemoryTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabasePoolReleaseMemoryTests.swift; sourceTree = "<group>"; };
|
||||
563363D41C94484E000BE133 /* DatabaseQueueReleaseMemoryTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseQueueReleaseMemoryTests.swift; sourceTree = "<group>"; };
|
||||
5634B1061CF9B970005360B9 /* TransactionObserverSavepointsTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TransactionObserverSavepointsTests.swift; sourceTree = "<group>"; };
|
||||
5636E9BB1D22574100B9B05F /* Request.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Request.swift; sourceTree = "<group>"; };
|
||||
5636E9BB1D22574100B9B05F /* FetchRequest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FetchRequest.swift; sourceTree = "<group>"; };
|
||||
564448821EF56B1B00DD2861 /* DatabaseAfterNextTransactionCommitTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseAfterNextTransactionCommitTests.swift; sourceTree = "<group>"; };
|
||||
564A50C61BFF4B7F00B3A3A2 /* DatabaseCollationTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseCollationTests.swift; sourceTree = "<group>"; };
|
||||
564E73E7203DA278000C443C /* JoinSupportTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JoinSupportTests.swift; sourceTree = "<group>"; };
|
||||
@@ -624,7 +626,7 @@
|
||||
5672DE581CDB72520022BA81 /* DatabaseQueueBackupTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseQueueBackupTests.swift; sourceTree = "<group>"; };
|
||||
5672DE661CDB751D0022BA81 /* DatabasePoolBackupTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabasePoolBackupTests.swift; sourceTree = "<group>"; };
|
||||
567404871CEF84C8003ED5CC /* RowAdapter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RowAdapter.swift; sourceTree = "<group>"; };
|
||||
56741EA71E66A8B3003E422D /* RequestTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RequestTests.swift; sourceTree = "<group>"; };
|
||||
56741EA71E66A8B3003E422D /* FetchRequestTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FetchRequestTests.swift; sourceTree = "<group>"; };
|
||||
5674A6E21F307F0E0095F066 /* DatabaseValueConvertible+Encodable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DatabaseValueConvertible+Encodable.swift"; sourceTree = "<group>"; };
|
||||
5674A6E31F307F0E0095F066 /* DatabaseValueConvertible+Decodable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DatabaseValueConvertible+Decodable.swift"; sourceTree = "<group>"; };
|
||||
5674A6F21F307F600095F066 /* RowConvertible+Decodable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "RowConvertible+Decodable.swift"; sourceTree = "<group>"; };
|
||||
@@ -669,6 +671,7 @@
|
||||
5698AD151DAAD16F0056AF8C /* FTS5Tokenizer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS5Tokenizer.swift; sourceTree = "<group>"; };
|
||||
5698AD201DABAEFA0056AF8C /* FTS5WrapperTokenizer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS5WrapperTokenizer.swift; sourceTree = "<group>"; };
|
||||
5698AD341DABAF4A0056AF8C /* FTS5CustomTokenizer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS5CustomTokenizer.swift; sourceTree = "<group>"; };
|
||||
569A98F62039B716008D7DBF /* Fixits-3.0.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Fixits-3.0.swift"; sourceTree = "<group>"; };
|
||||
569B7FA2201C90430069DE70 /* Swift4.1.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Swift4.1.swift; sourceTree = "<group>"; };
|
||||
569C1EB11CF07DDD0042627B /* SchedulingWatchdogTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SchedulingWatchdogTests.swift; sourceTree = "<group>"; };
|
||||
569EF0E5200D37FC00A9FA45 /* DatabaseRegion.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseRegion.swift; sourceTree = "<group>"; };
|
||||
@@ -1005,8 +1008,8 @@
|
||||
56CEB5401EAA359A00BFAF62 /* Column.swift */,
|
||||
56CEB5101EAA324B00BFAF62 /* FTS3+QueryInterfaceRequest.swift */,
|
||||
56CEB5181EAA328900BFAF62 /* FTS5+QueryInterface.swift */,
|
||||
5605F18C1C6B1A8700235C62 /* QueryInterfaceQuery.swift */,
|
||||
56300B6F1C53F592005A543B /* QueryInterfaceRequest.swift */,
|
||||
5605F18C1C6B1A8700235C62 /* QueryInterfaceSelectQueryDefinition.swift */,
|
||||
5605F1891C6B1A8700235C62 /* SQLCollatedExpression.swift */,
|
||||
566475991D97D8A000FF74B8 /* SQLCollection.swift */,
|
||||
56CEB5411EAA359A00BFAF62 /* SQLExpressible.swift */,
|
||||
@@ -1138,11 +1141,11 @@
|
||||
56A238191B9C74A90082EB20 /* DatabaseValueConvertible */,
|
||||
56A238181B9C74A90082EB20 /* DatabaseValueTests.swift */,
|
||||
562756421E963AAC0035B653 /* DatabaseWriterTests.swift */,
|
||||
56741EA71E66A8B3003E422D /* FetchRequestTests.swift */,
|
||||
56A5EF0E1EF7F20B00F03071 /* ForeignKeyInfoTests.swift */,
|
||||
567A80521D41350C00C7DCEC /* IndexInfoTests.swift */,
|
||||
56D5075D1F6BAE8600AE1C5B /* PrimaryKeyInfoTests.swift */,
|
||||
565EFAED1D0436CE00A8FA9D /* NumericOverflowTests.swift */,
|
||||
56741EA71E66A8B3003E422D /* RequestTests.swift */,
|
||||
56F3E7481E66F83A00BF0F01 /* ResultCodeTests.swift */,
|
||||
56A2381D1B9C74A90082EB20 /* Row */,
|
||||
569C1EB11CF07DDD0042627B /* SchedulingWatchdogTests.swift */,
|
||||
@@ -1233,7 +1236,7 @@
|
||||
56A238751B9C75030082EB20 /* DatabaseValue.swift */,
|
||||
560D923E1C672C3E00F4F92B /* DatabaseValueConvertible.swift */,
|
||||
563363C31C942C37000BE133 /* DatabaseWriter.swift */,
|
||||
5636E9BB1D22574100B9B05F /* Request.swift */,
|
||||
5636E9BB1D22574100B9B05F /* FetchRequest.swift */,
|
||||
56A238761B9C75030082EB20 /* Row.swift */,
|
||||
567404871CEF84C8003ED5CC /* RowAdapter.swift */,
|
||||
56BB6EA81D3009B100A1CA52 /* SchedulingWatchdog.swift */,
|
||||
@@ -1282,6 +1285,7 @@
|
||||
56E06F051E859064008AE2A4 /* Fixits-0.102.0.swift */,
|
||||
56D121591ED34978001347D2 /* Fixits-0.109.0.swift */,
|
||||
56873BEB1F2CB400004D24B4 /* Fixits-1.2.swift */,
|
||||
569A98F62039B716008D7DBF /* Fixits-3.0.swift */,
|
||||
569B7FA2201C90430069DE70 /* Swift4.1.swift */,
|
||||
);
|
||||
path = Legacy;
|
||||
@@ -1690,7 +1694,7 @@
|
||||
files = (
|
||||
56873BF11F2CB400004D24B4 /* Fixits-1.2.swift in Sources */,
|
||||
56BF6D421DEF47DA006039A3 /* Fixits-Swift2.swift in Sources */,
|
||||
5636E9C11D22574100B9B05F /* Request.swift in Sources */,
|
||||
5636E9C11D22574100B9B05F /* FetchRequest.swift in Sources */,
|
||||
F3BA801B1CFB2886003DC1BA /* CGFloat.swift in Sources */,
|
||||
566B910E1FA4C3970012D5B0 /* Database+Statements.swift in Sources */,
|
||||
566B91281FA4CF810012D5B0 /* Database+Schema.swift in Sources */,
|
||||
@@ -1731,7 +1735,7 @@
|
||||
F3BA80131CFB2876003DC1BA /* DatabaseValue.swift in Sources */,
|
||||
56B964B61DA51D010002DA19 /* FTS5TokenizerDescriptor.swift in Sources */,
|
||||
F3BA80171CFB2876003DC1BA /* RowAdapter.swift in Sources */,
|
||||
F3BA802F1CFB289B003DC1BA /* QueryInterfaceSelectQueryDefinition.swift in Sources */,
|
||||
F3BA802F1CFB289B003DC1BA /* QueryInterfaceQuery.swift in Sources */,
|
||||
56CEB5061EAA2F4D00BFAF62 /* FTS4.swift in Sources */,
|
||||
56CEB55F1EAA359A00BFAF62 /* SQLOrdering.swift in Sources */,
|
||||
F3BA80201CFB288C003DC1BA /* Date.swift in Sources */,
|
||||
@@ -1769,6 +1773,7 @@
|
||||
566AD8B71D5318F4002EC1A8 /* TableDefinition.swift in Sources */,
|
||||
5698AD261DABAEFA0056AF8C /* FTS5WrapperTokenizer.swift in Sources */,
|
||||
F3BA802C1CFB289B003DC1BA /* SQLCollatedExpression.swift in Sources */,
|
||||
569A98F92039B716008D7DBF /* Fixits-3.0.swift in Sources */,
|
||||
F3BA80301CFB289F003DC1BA /* DatabaseMigrator.swift in Sources */,
|
||||
F3BA80361CFB28A4003DC1BA /* TableMapping.swift in Sources */,
|
||||
F3BA80271CFB2891003DC1BA /* DatabaseValueConvertible+RawRepresentable.swift in Sources */,
|
||||
@@ -1909,7 +1914,7 @@
|
||||
5698AC901DA389380056AF8C /* FTS3TableBuilderTests.swift in Sources */,
|
||||
568068381EBBA26100EFB8AA /* SQLRequestTests.swift in Sources */,
|
||||
F3BA80DB1CFB300E003DC1BA /* DatabaseValueConversionTests.swift in Sources */,
|
||||
56741EAF1E66A8B3003E422D /* RequestTests.swift in Sources */,
|
||||
56741EAF1E66A8B3003E422D /* FetchRequestTests.swift in Sources */,
|
||||
5657AB5D1D108BA9006283EF /* FoundationNSStringTests.swift in Sources */,
|
||||
F3BA81241CFB3063003DC1BA /* RecordPrimaryKeySingleWithReplaceConflictResolutionTests.swift in Sources */,
|
||||
5674A71F1F30A8DF0095F066 /* MutablePersistableEncodableTests.swift in Sources */,
|
||||
@@ -1937,7 +1942,7 @@
|
||||
files = (
|
||||
56873BEE1F2CB400004D24B4 /* Fixits-1.2.swift in Sources */,
|
||||
56BF6D3F1DEF47DA006039A3 /* Fixits-Swift2.swift in Sources */,
|
||||
5636E9BE1D22574100B9B05F /* Request.swift in Sources */,
|
||||
5636E9BE1D22574100B9B05F /* FetchRequest.swift in Sources */,
|
||||
F3BA80771CFB2E5C003DC1BA /* CGFloat.swift in Sources */,
|
||||
566B910B1FA4C3970012D5B0 /* Database+Statements.swift in Sources */,
|
||||
566B91251FA4CF810012D5B0 /* Database+Schema.swift in Sources */,
|
||||
@@ -1978,7 +1983,7 @@
|
||||
F3BA806F1CFB2E55003DC1BA /* DatabaseValue.swift in Sources */,
|
||||
56B964B31DA51D010002DA19 /* FTS5TokenizerDescriptor.swift in Sources */,
|
||||
F3BA80731CFB2E55003DC1BA /* RowAdapter.swift in Sources */,
|
||||
F3BA808B1CFB2E70003DC1BA /* QueryInterfaceSelectQueryDefinition.swift in Sources */,
|
||||
F3BA808B1CFB2E70003DC1BA /* QueryInterfaceQuery.swift in Sources */,
|
||||
56CEB5031EAA2F4D00BFAF62 /* FTS4.swift in Sources */,
|
||||
56CEB55C1EAA359A00BFAF62 /* SQLOrdering.swift in Sources */,
|
||||
F3BA807C1CFB2E61003DC1BA /* Date.swift in Sources */,
|
||||
@@ -2016,6 +2021,7 @@
|
||||
566AD8B41D5318F4002EC1A8 /* TableDefinition.swift in Sources */,
|
||||
5698AD231DABAEFA0056AF8C /* FTS5WrapperTokenizer.swift in Sources */,
|
||||
F3BA80881CFB2E70003DC1BA /* SQLCollatedExpression.swift in Sources */,
|
||||
569A98F82039B716008D7DBF /* Fixits-3.0.swift in Sources */,
|
||||
F3BA808C1CFB2E75003DC1BA /* DatabaseMigrator.swift in Sources */,
|
||||
F3BA80921CFB2E7A003DC1BA /* TableMapping.swift in Sources */,
|
||||
F3BA80831CFB2E67003DC1BA /* DatabaseValueConvertible+RawRepresentable.swift in Sources */,
|
||||
@@ -2157,7 +2163,7 @@
|
||||
F3BA81351CFB3064003DC1BA /* RecordEditedTests.swift in Sources */,
|
||||
568068341EBBA26100EFB8AA /* SQLRequestTests.swift in Sources */,
|
||||
5657AB691D108BA9006283EF /* FoundationURLTests.swift in Sources */,
|
||||
56741EAB1E66A8B3003E422D /* RequestTests.swift in Sources */,
|
||||
56741EAB1E66A8B3003E422D /* FetchRequestTests.swift in Sources */,
|
||||
56B964D61DA521450002DA19 /* FTS5TableBuilderTests.swift in Sources */,
|
||||
5674A71D1F30A8DF0095F066 /* MutablePersistableEncodableTests.swift in Sources */,
|
||||
562393511DEDFEFB00A6B01F /* EnumeratedCursorTests.swift in Sources */,
|
||||
|
||||
@@ -3707,14 +3707,13 @@ Until now, we have seen [requests](#requests) created from any type that adopts
|
||||
let request = Player.all() // QueryInterfaceRequest<Player>
|
||||
```
|
||||
|
||||
Those requests of type `QueryInterfaceRequest` can fetch, count, and delete records:
|
||||
Those requests of type `QueryInterfaceRequest` can fetch and count:
|
||||
|
||||
```swift
|
||||
try request.fetchCursor(db) // A Cursor of Player
|
||||
try request.fetchAll(db) // [Player]
|
||||
try request.fetchOne(db) // Player?
|
||||
try request.fetchCount(db) // Int
|
||||
try request.deleteAll(db)
|
||||
```
|
||||
|
||||
**When the query interface can not generate the SQL you need**, you can still fallback to [raw SQL](#fetch-queries):
|
||||
@@ -3724,86 +3723,104 @@ try request.deleteAll(db)
|
||||
try Player.fetchAll(db, "SELECT ...") // [Player]
|
||||
```
|
||||
|
||||
But you may prefer to bring some elegance back in, and build custom requests on top of the `Request` and `TypedRequest` protocols:
|
||||
But you may prefer to bring some elegance back in, and build custom requests on top of the `FetchRequest` protocol:
|
||||
|
||||
```swift
|
||||
// No custom SQL in sight
|
||||
try Player.customRequest().fetchAll(db) // [Player]
|
||||
```
|
||||
|
||||
Unlike QueryInterfaceRequest, these protocols can't delete. But they can fetch and count:
|
||||
Custom requests also grant [FetchedRecordsController](#fetchedrecordscontroller) and [RxGRDB](http://github.com/RxSwiftCommunity/RxGRDB) the ability to observe the database:
|
||||
|
||||
```swift
|
||||
/// The protocol for all types that define a way to fetch database rows.
|
||||
protocol Request {
|
||||
/// A tuple that contains a prepared statement that is ready to be
|
||||
/// executed, and an eventual row adapter.
|
||||
Player.customRequest(...).rx
|
||||
.fetchAll(in: dbQueue)
|
||||
.subscribe(onNext: { players: [Player] in
|
||||
print("Players have changed")
|
||||
})
|
||||
```
|
||||
|
||||
|
||||
### FetchRequest Protocol
|
||||
|
||||
**FetchRequest is the protocol for all types that define a way to fetch database rows:**
|
||||
|
||||
```swift
|
||||
protocol FetchRequest {
|
||||
/// The type that tells how fetched rows should be decoded
|
||||
associatedtype RowDecoder
|
||||
|
||||
/// A tuple that contains a prepared statement, and an eventual row adapter.
|
||||
func prepare(_ db: Database) throws -> (SelectStatement, RowAdapter?)
|
||||
|
||||
/// The number of rows fetched by the request.
|
||||
func fetchCount(_ db: Database) throws -> Int
|
||||
}
|
||||
|
||||
/// The protocol for requests that know how to decode database rows.
|
||||
protocol TypedRequest : Request {
|
||||
/// The type that can convert raw database rows to fetched values
|
||||
associatedtype RowDecoder
|
||||
|
||||
/// The database region that the request looks into.
|
||||
func fetchedRegion(_ db: Database) throws -> DatabaseRegion
|
||||
}
|
||||
```
|
||||
|
||||
The `prepare` method returns a tuple made of a [prepared statement](#prepared-statements) and an optional [row adapter](#row-adapters). The prepared statement tells which SQL query should be executed. The row adapter can help *presenting* the fetched rows in the way expected by the row consumers (we'll see an example below).
|
||||
The `RowDecoder` associated type tells a request how to decode rows. It can be any type, but not all types have built-in support. See [Fetching From Custom Requests](#fetching-from-custom-requests) below.
|
||||
|
||||
The `prepare` method returns a prepared statement and an optional row adapter. The [prepared statement](#prepared-statements) tells which SQL query should be executed. The row adapter helps presenting the fetched rows in the way expected by the row decoders (see [row adapter](#row-adapters)).
|
||||
|
||||
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.
|
||||
|
||||
|
||||
### Fetching From Custom Requests
|
||||
|
||||
A Request doesn't know what to fetch, but it can feed the [fetching methods](#fetching-methods) of any fetchable type ([Row](#fetching-rows), [value](#value-queries), or [record](#records)):
|
||||
|
||||
```swift
|
||||
let request: Request = ...
|
||||
try Row.fetchCursor(db, request) // A Cursor of Row
|
||||
try String.fetchAll(db, request) // [String]
|
||||
try Player.fetchOne(db, request) // Player?
|
||||
```
|
||||
|
||||
On top of that, a TypedRequest knows exactly what it has to do when its RowDecoder associated type can decode database rows ([Row](#fetching-rows) itself, [values](#value-queries), or [records](#records)):
|
||||
|
||||
```swift
|
||||
let request = ... // Some TypedRequest that fetches Player
|
||||
try request.fetchCursor(db) // A Cursor of Player
|
||||
try request.fetchAll(db) // [Player]
|
||||
try request.fetchOne(db) // Player?
|
||||
```
|
||||
The `fetchedRegion` method helps [transaction observers](#transactionobserver-protocol) efficiently track modifications in requests results. It has a default implementation that you can't really improve in the current state of the API.
|
||||
|
||||
|
||||
### Building Custom Requests
|
||||
|
||||
**To build custom requests**, you can create your own type that adopts the protocols, or derive requests from other requests, or use one of the built-in concrete types:
|
||||
**To build custom requests**, you can create your own type that adopts the [FetchRequest](#fetchrequest-protocol) protocol, derive requests from other requests, or use one of the built-in concrete types:
|
||||
|
||||
- [SQLRequest](http://groue.github.io/GRDB.swift/docs/2.9/Structs/SQLRequest.html): a Request built from raw SQL
|
||||
- [AnyRequest](http://groue.github.io/GRDB.swift/docs/2.9/Structs/AnyRequest.html): a type-erased Request
|
||||
- [AnyTypedRequest](http://groue.github.io/GRDB.swift/docs/2.9/Structs/AnyTypedRequest.html): a type-erased TypedRequest
|
||||
- [SQLRequest](http://groue.github.io/GRDB.swift/docs/2.9/Structs/SQLRequest.html) is a fetch request built from raw SQL. For example:
|
||||
|
||||
```swift
|
||||
extension Player {
|
||||
static func filter(color: Color) -> SQLRequest<Player> {
|
||||
let request = SQLRequest<Player>(
|
||||
"SELECT * FROM players WHERE color = ?"
|
||||
arguments: [color])
|
||||
}
|
||||
}
|
||||
|
||||
// [Player]
|
||||
try Player.filter(color: .red).fetchAll(db)
|
||||
```
|
||||
|
||||
- The `asRequest(of:)` method changes the type fetched by the request:
|
||||
|
||||
Use the `asRequest(of:)` method to define the type fetched by the request:
|
||||
```swift
|
||||
// Int?
|
||||
let maxScore = Player.select(max(Column("score")))
|
||||
.asRequest(of: Int.self)
|
||||
.fetchOne(db)
|
||||
```
|
||||
|
||||
- The `adapted(_:)` method eases the consumption of complex rows with [row adapters](#row-adapters). See [Joined Queries Support](#joined-queries-support) for some sample code that uses this method.
|
||||
|
||||
- [AnyFetchRequest](http://groue.github.io/GRDB.swift/docs/2.9/Structs/AnyFetchRequest.html): a [type-erased](http://chris.eidhof.nl/post/type-erasers-in-swift/) request.
|
||||
|
||||
|
||||
### Fetching From Custom Requests
|
||||
|
||||
A fetch request knows exactly what it has to do when its RowDecoder associated type can decode database rows ([Row](#fetching-rows) itself, [values](#value-queries), or [records](#records)):
|
||||
|
||||
```swift
|
||||
let maxScore = Player.select(max(scoreColumn))
|
||||
.asRequest(of: Int.self)
|
||||
.fetchOne(db)
|
||||
let rowRequest = ... // Some TypedRequest that fetches Row
|
||||
try request.fetchCursor(db) // A cursor of rows
|
||||
|
||||
extension Player {
|
||||
static func customRequest(...) -> AnyTypedRequest<Player> {
|
||||
let request = SQLRequest("SELECT ...", arguments: ...)
|
||||
return request.asRequest(of: Player.self)
|
||||
}
|
||||
}
|
||||
let playerRequest = ... // Some TypedRequest that fetches Player
|
||||
try request.fetchAll(db) // [Player]
|
||||
|
||||
try Player.customRequest(...).fetchAll(db) // [Player]
|
||||
try Player.customRequest(...).fetchCount(db) // Int
|
||||
let intRequest = ... // Some TypedRequest that fetches Int
|
||||
try request.fetchOne(db) // Int?
|
||||
```
|
||||
|
||||
Finally, use the `adapted(_:)` method to ease the consumption of complex rows with [row adapters](#row-adapters). See [Joined Queries Support](#joined-queries-support) for more information.
|
||||
See [fetching methods](#fetching-methods) for information about the `fetchCursor`, `fetchAll` and `fetchOne` methods.
|
||||
|
||||
When RowDecoder is another type, you can write your own convenience methods.
|
||||
|
||||
|
||||
Application Tools
|
||||
@@ -4822,7 +4839,7 @@ Now we write a method that returns a request, and build the fetching method on t
|
||||
```swift
|
||||
extension Item {
|
||||
/// The request for all items
|
||||
static func all() -> AnyTypedRequest<Item> {
|
||||
static func all() -> AdaptedFetchRequest<SQLRequest<Item>> {
|
||||
let sql = """
|
||||
SELECT
|
||||
\(Player.selectionSQL()),
|
||||
@@ -4833,15 +4850,14 @@ extension Item {
|
||||
LEFT JOIN rounds ON ...
|
||||
GROUP BY ...
|
||||
"""
|
||||
return SQLRequest(sql).adapted { db in
|
||||
return SQLRequest<Item>(sql).adapted { db in
|
||||
let adapters = try splittingRowAdapters(columnCounts: [
|
||||
Player.numberOfSelectedColumns(db),
|
||||
Team.numberOfSelectedColumns(db)])
|
||||
return ScopeAdapter([
|
||||
Scopes.player: adapters[0],
|
||||
Scopes.team: adapters[1]])
|
||||
}
|
||||
.asRequest(of: Item.self)
|
||||
}
|
||||
}
|
||||
|
||||
/// Fetches all items
|
||||
@@ -4896,7 +4912,7 @@ struct Item: Decodable, RowConvertible {
|
||||
|
||||
extension Item {
|
||||
/// The request for all items
|
||||
static func all() -> AnyTypedRequest<Item> {
|
||||
static func all() -> AdaptedFetchRequest<SQLRequest<Item>> {
|
||||
let sql = """
|
||||
SELECT
|
||||
\(Player.selectionSQL()),
|
||||
@@ -4907,15 +4923,14 @@ extension Item {
|
||||
LEFT JOIN rounds ON ...
|
||||
GROUP BY ...
|
||||
"""
|
||||
return SQLRequest(sql).adapted { db in
|
||||
return SQLRequest<Item>(sql).adapted { db in
|
||||
let adapters = try splittingRowAdapters(columnCounts: [
|
||||
Player.numberOfSelectedColumns(db),
|
||||
Team.numberOfSelectedColumns(db)])
|
||||
return ScopeAdapter([
|
||||
CodingKeys.player.stringValue: adapters[0],
|
||||
CodingKeys.team.stringValue: adapters[1]])
|
||||
}
|
||||
.asRequest(of: Item.self)
|
||||
}
|
||||
}
|
||||
|
||||
/// Fetches all items
|
||||
|
||||
@@ -20,7 +20,7 @@ Xcode 9.3, Swift 4.1
|
||||
GRDB 3.0
|
||||
|
||||
- [ ] Rename "changes tracking" (ambiguous with database observation) to "record comparison"
|
||||
- [ ] Refactor SQL generation and rowId extraction from expression on the visitor pattern. Provide more documentation for literal expressions which become the only way to extend GRDB.
|
||||
- [ ] Refactor SQL generation and rowId extraction from expression on the visitor pattern. Provide more documentation for literal expressions which become the only way to extend GRDB. Remove QueryInterfaceExtensibilityTests.swift
|
||||
- [ ] Hide useless scheduling methods behind protocols : https://forums.swift.org/t/discouraging-protocol-methods-on-concrete-values/8737/4?u=gwendal.roue
|
||||
- [ ] Make DatabasePool.write safe. See https://github.com/groue/GRDB.swift/commit/5e3c7d9c430df606a1cccfd4983be6b50e778a5c#commitcomment-26988970
|
||||
- [ ] Do one of those two:
|
||||
@@ -34,7 +34,8 @@ GRDB 3.0
|
||||
- [ ] Rename RowConvertible, TableMapping, MutablePersistable and Persistable so that their names contain Record: FetchableRecord, TableRecord, MutablePersistableRecord, PersistableRecord?
|
||||
- [ ] Not sure: Consider introducing RowDecodable and RowEncodable on top of FetchableRecord and MutablePersistableRecord. This would allow keeping fetching and persistence methods private in some files.
|
||||
- [ ] Drop IteratorCursor, use AnyCursor instead
|
||||
- [ ] Drop TypedRequest, have FetchRequest defaults to Row requests.
|
||||
<<<<<<< HEAD
|
||||
- [X] Rename TypedRequest to FetchRequest, drop Request
|
||||
- [ ] Rename columnCount -> numberOfColumns
|
||||
- [ ] Try to remove double Persistable/MutablePersistable protocols: Would non-mutating Record methods help?
|
||||
|
||||
|
||||
@@ -134,13 +134,11 @@ private class UserPersistable2 : Persistable {
|
||||
func encode(to container: inout PersistenceContainer) { }
|
||||
}
|
||||
|
||||
// MARK: - Request
|
||||
// MARK: - FetchRequest
|
||||
|
||||
private struct UserRequest1 : Request {
|
||||
func prepare(_ db: Database) throws -> (SelectStatement, RowAdapter?) { preconditionFailure() }
|
||||
}
|
||||
|
||||
private class UserRequest2 : Request {
|
||||
private struct UserRowRequest : FetchRequest {
|
||||
struct CustomType { }
|
||||
typealias RowDecoder = CustomType
|
||||
func prepare(_ db: Database) throws -> (SelectStatement, RowAdapter?) { preconditionFailure() }
|
||||
}
|
||||
|
||||
@@ -174,19 +172,6 @@ private class UserTableMapping2 : TableMapping {
|
||||
static let databaseTableName = "UserTableMapping2"
|
||||
}
|
||||
|
||||
// MARK: - TypedRequest
|
||||
|
||||
private struct UserTypedRequest1 : TypedRequest {
|
||||
struct CustomType { }
|
||||
typealias RowDecoder = CustomType
|
||||
func prepare(_ db: Database) throws -> (SelectStatement, RowAdapter?) { preconditionFailure() }
|
||||
}
|
||||
|
||||
private class UserTypedRequest2<T> : TypedRequest {
|
||||
typealias RowDecoder = T
|
||||
func prepare(_ db: Database) throws -> (SelectStatement, RowAdapter?) { preconditionFailure() }
|
||||
}
|
||||
|
||||
// MARK: - TransactionObserver
|
||||
|
||||
private class UserTransactionObserver : TransactionObserver {
|
||||
|
||||
@@ -422,28 +422,16 @@ class DatabaseRegionTests : GRDBTestCase {
|
||||
try XCTAssertEqual(request.fetchedRegion(db).description, "foo(a,id)[1,2,3]")
|
||||
|
||||
do {
|
||||
let derivedRequest: AnyRequest = AnyRequest(request)
|
||||
let derivedRequest: AnyFetchRequest<Row> = AnyFetchRequest(request)
|
||||
try XCTAssertEqual(derivedRequest.fetchedRegion(db).description, "foo(a,id)[1,2,3]")
|
||||
}
|
||||
do {
|
||||
let derivedRequest: AnyTypedRequest<Record> = AnyTypedRequest(request)
|
||||
try XCTAssertEqual(derivedRequest.fetchedRegion(db).description, "foo(a,id)[1,2,3]")
|
||||
}
|
||||
do {
|
||||
let derivedRequest: AnyTypedRequest<Row> = request.asRequest(of: Row.self)
|
||||
try XCTAssertEqual(derivedRequest.fetchedRegion(db).description, "foo(a,id)[1,2,3]")
|
||||
}
|
||||
do {
|
||||
let derivedRequest: AdaptedTypedRequest = request.adapted { db in SuffixRowAdapter(fromIndex: 1) }
|
||||
try XCTAssertEqual(derivedRequest.fetchedRegion(db).description, "foo(a,id)[1,2,3]")
|
||||
}
|
||||
do {
|
||||
let derivedRequest: AdaptedRequest = AnyRequest(request).adapted { db in SuffixRowAdapter(fromIndex: 1) }
|
||||
let derivedRequest: AdaptedFetchRequest = request.adapted { db in SuffixRowAdapter(fromIndex: 1) }
|
||||
try XCTAssertEqual(derivedRequest.fetchedRegion(db).description, "foo(a,id)[1,2,3]")
|
||||
}
|
||||
do {
|
||||
// SQL request loses region info
|
||||
let derivedRequest: SQLRequest = try request.asSQLRequest(db)
|
||||
let derivedRequest = try SQLRequest(db, request: request)
|
||||
try XCTAssertEqual(derivedRequest.fetchedRegion(db).description, "foo(a,id)")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,8 +41,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase {
|
||||
let statement = try db.makeSelectStatement(sql)
|
||||
try test(Fetched.fetchCursor(db, sql))
|
||||
try test(Fetched.fetchCursor(statement))
|
||||
try test(Fetched.fetchCursor(db, SQLRequest(sql)))
|
||||
try test(SQLRequest(sql).asRequest(of: Fetched.self).fetchCursor(db))
|
||||
try test(SQLRequest<Fetched>(sql).fetchCursor(db))
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT 0, 1 UNION ALL SELECT 0, 2"
|
||||
@@ -50,8 +49,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase {
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
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).asRequest(of: Fetched.self).fetchCursor(db))
|
||||
try test(SQLRequest<Fetched>(sql, adapter: adapter).fetchCursor(db))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -85,16 +83,14 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase {
|
||||
let sql = "SELECT throw()"
|
||||
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).asRequest(of: Fetched.self).fetchCursor(db), sql: sql)
|
||||
try test(SQLRequest<Fetched>(sql).fetchCursor(db), sql: sql)
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT 0, throw()"
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
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).asRequest(of: Fetched.self).fetchCursor(db), sql: sql)
|
||||
try test(SQLRequest<Fetched>(sql, adapter: adapter).fetchCursor(db), sql: sql)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -117,16 +113,14 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase {
|
||||
let sql = "SELECT * FROM nonExistingTable"
|
||||
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).asRequest(of: Fetched.self).fetchCursor(db), sql: sql)
|
||||
try test(SQLRequest<Fetched>(sql).fetchCursor(db), sql: sql)
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT * FROM nonExistingTable"
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
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).asRequest(of: Fetched.self).fetchCursor(db), sql: sql)
|
||||
try test(SQLRequest<Fetched>(sql, adapter: adapter).fetchCursor(db), sql: sql)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -142,8 +136,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase {
|
||||
let statement = try db.makeSelectStatement(sql)
|
||||
try test(Fetched.fetchAll(db, sql))
|
||||
try test(Fetched.fetchAll(statement))
|
||||
try test(Fetched.fetchAll(db, SQLRequest(sql)))
|
||||
try test(SQLRequest(sql).asRequest(of: Fetched.self).fetchAll(db))
|
||||
try test(SQLRequest<Fetched>(sql).fetchAll(db))
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT 0, 1 UNION ALL SELECT 0, 2"
|
||||
@@ -151,8 +144,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase {
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
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).asRequest(of: Fetched.self).fetchAll(db))
|
||||
try test(SQLRequest<Fetched>(sql, adapter: adapter).fetchAll(db))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -177,16 +169,14 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase {
|
||||
let sql = "SELECT throw()"
|
||||
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).asRequest(of: Fetched.self).fetchAll(db), sql: sql)
|
||||
try test(SQLRequest<Fetched>(sql).fetchAll(db), sql: sql)
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT 0, throw()"
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
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).asRequest(of: Fetched.self).fetchAll(db), sql: sql)
|
||||
try test(SQLRequest<Fetched>(sql, adapter: adapter).fetchAll(db), sql: sql)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -209,16 +199,14 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase {
|
||||
let sql = "SELECT * FROM nonExistingTable"
|
||||
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).asRequest(of: Fetched.self).fetchAll(db), sql: sql)
|
||||
try test(SQLRequest<Fetched>(sql).fetchAll(db), sql: sql)
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT * FROM nonExistingTable"
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
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).asRequest(of: Fetched.self).fetchAll(db), sql: sql)
|
||||
try test(SQLRequest<Fetched>(sql, adapter: adapter).fetchAll(db), sql: sql)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -235,8 +223,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase {
|
||||
let statement = try db.makeSelectStatement(sql)
|
||||
try test(Fetched.fetchOne(db, sql))
|
||||
try test(Fetched.fetchOne(statement))
|
||||
try test(Fetched.fetchOne(db, SQLRequest(sql)))
|
||||
try test(SQLRequest(sql).asRequest(of: Fetched.self).fetchOne(db))
|
||||
try test(SQLRequest<Fetched>(sql).fetchOne(db))
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT 0, 1 WHERE 0"
|
||||
@@ -244,8 +231,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase {
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
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).asRequest(of: Fetched.self).fetchOne(db))
|
||||
try test(SQLRequest<Fetched>(sql, adapter: adapter).fetchOne(db))
|
||||
}
|
||||
}
|
||||
do {
|
||||
@@ -257,8 +243,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase {
|
||||
let statement = try db.makeSelectStatement(sql)
|
||||
try test(Fetched.fetchOne(db, sql))
|
||||
try test(Fetched.fetchOne(statement))
|
||||
try test(Fetched.fetchOne(db, SQLRequest(sql)))
|
||||
try test(SQLRequest(sql).asRequest(of: Fetched.self).fetchOne(db))
|
||||
try test(SQLRequest<Fetched>(sql).fetchOne(db))
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT 0, NULL"
|
||||
@@ -266,8 +251,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase {
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
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).asRequest(of: Fetched.self).fetchOne(db))
|
||||
try test(SQLRequest<Fetched>(sql, adapter: adapter).fetchOne(db))
|
||||
}
|
||||
}
|
||||
do {
|
||||
@@ -279,8 +263,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase {
|
||||
let statement = try db.makeSelectStatement(sql)
|
||||
try test(Fetched.fetchOne(db, sql))
|
||||
try test(Fetched.fetchOne(statement))
|
||||
try test(Fetched.fetchOne(db, SQLRequest(sql)))
|
||||
try test(SQLRequest(sql).asRequest(of: Fetched.self).fetchOne(db))
|
||||
try test(SQLRequest<Fetched>(sql).fetchOne(db))
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT 0, 1"
|
||||
@@ -288,8 +271,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase {
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
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).asRequest(of: Fetched.self).fetchOne(db))
|
||||
try test(SQLRequest<Fetched>(sql, adapter: adapter).fetchOne(db))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -315,16 +297,14 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase {
|
||||
let sql = "SELECT throw()"
|
||||
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).asRequest(of: Fetched.self).fetchOne(db), sql: sql)
|
||||
try test(SQLRequest<Fetched>(sql).fetchOne(db), sql: sql)
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT 0, throw()"
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
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).asRequest(of: Fetched.self).fetchOne(db), sql: sql)
|
||||
try test(SQLRequest<Fetched>(sql, adapter: adapter).fetchOne(db), sql: sql)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -347,16 +327,14 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase {
|
||||
let sql = "SELECT * FROM nonExistingTable"
|
||||
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).asRequest(of: Fetched.self).fetchOne(db), sql: sql)
|
||||
try test(SQLRequest<Fetched>(sql).fetchOne(db), sql: sql)
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT * FROM nonExistingTable"
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
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).asRequest(of: Fetched.self).fetchOne(db), sql: sql)
|
||||
try test(SQLRequest<Fetched>(sql, adapter: adapter).fetchOne(db), sql: sql)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -376,8 +354,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase {
|
||||
let statement = try db.makeSelectStatement(sql)
|
||||
try test(Optional<Fetched>.fetchCursor(db, sql))
|
||||
try test(Optional<Fetched>.fetchCursor(statement))
|
||||
try test(Optional<Fetched>.fetchCursor(db, SQLRequest(sql)))
|
||||
try test(SQLRequest(sql).asRequest(of: Optional<Fetched>.self).fetchCursor(db))
|
||||
try test(SQLRequest<Fetched?>(sql).fetchCursor(db))
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT 0, 1 UNION ALL SELECT 0, NULL"
|
||||
@@ -385,8 +362,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase {
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
try test(Optional<Fetched>.fetchCursor(db, sql, adapter: adapter))
|
||||
try test(Optional<Fetched>.fetchCursor(statement, adapter: adapter))
|
||||
try test(Optional<Fetched>.fetchCursor(db, SQLRequest(sql, adapter: adapter)))
|
||||
try test(SQLRequest(sql, adapter: adapter).asRequest(of: Optional<Fetched>.self).fetchCursor(db))
|
||||
try test(SQLRequest<Fetched?>(sql, adapter: adapter).fetchCursor(db))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -420,16 +396,14 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase {
|
||||
let sql = "SELECT throw()"
|
||||
try test(Optional<Fetched>.fetchCursor(db, sql), sql: sql)
|
||||
try test(Optional<Fetched>.fetchCursor(db.makeSelectStatement(sql)), sql: sql)
|
||||
try test(Optional<Fetched>.fetchCursor(db, SQLRequest(sql)), sql: sql)
|
||||
try test(SQLRequest(sql).asRequest(of: Optional<Fetched>.self).fetchCursor(db), sql: sql)
|
||||
try test(SQLRequest<Fetched?>(sql).fetchCursor(db), sql: sql)
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT 0, throw()"
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
try test(Optional<Fetched>.fetchCursor(db, sql, adapter: adapter), sql: sql)
|
||||
try test(Optional<Fetched>.fetchCursor(db.makeSelectStatement(sql), adapter: adapter), sql: sql)
|
||||
try test(Optional<Fetched>.fetchCursor(db, SQLRequest(sql, adapter: adapter)), sql: sql)
|
||||
try test(SQLRequest(sql, adapter: adapter).asRequest(of: Optional<Fetched>.self).fetchCursor(db), sql: sql)
|
||||
try test(SQLRequest<Fetched?>(sql, adapter: adapter).fetchCursor(db), sql: sql)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -452,16 +426,14 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase {
|
||||
let sql = "SELECT * FROM nonExistingTable"
|
||||
try test(Optional<Fetched>.fetchCursor(db, sql), sql: sql)
|
||||
try test(Optional<Fetched>.fetchCursor(db.makeSelectStatement(sql)), sql: sql)
|
||||
try test(Optional<Fetched>.fetchCursor(db, SQLRequest(sql)), sql: sql)
|
||||
try test(SQLRequest(sql).asRequest(of: Optional<Fetched>.self).fetchCursor(db), sql: sql)
|
||||
try test(SQLRequest<Fetched?>(sql).fetchCursor(db), sql: sql)
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT * FROM nonExistingTable"
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
try test(Optional<Fetched>.fetchCursor(db, sql, adapter: adapter), sql: sql)
|
||||
try test(Optional<Fetched>.fetchCursor(db.makeSelectStatement(sql), adapter: adapter), sql: sql)
|
||||
try test(Optional<Fetched>.fetchCursor(db, SQLRequest(sql, adapter: adapter)), sql: sql)
|
||||
try test(SQLRequest(sql, adapter: adapter).asRequest(of: Optional<Fetched>.self).fetchCursor(db), sql: sql)
|
||||
try test(SQLRequest<Fetched?>(sql, adapter: adapter).fetchCursor(db), sql: sql)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -479,8 +451,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase {
|
||||
let statement = try db.makeSelectStatement(sql)
|
||||
try test(Optional<Fetched>.fetchAll(db, sql))
|
||||
try test(Optional<Fetched>.fetchAll(statement))
|
||||
try test(Optional<Fetched>.fetchAll(db, SQLRequest(sql)))
|
||||
try test(SQLRequest(sql).asRequest(of: Optional<Fetched>.self).fetchAll(db))
|
||||
try test(SQLRequest<Fetched?>(sql).fetchAll(db))
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT 0, 1 UNION ALL SELECT 0, NULL"
|
||||
@@ -488,8 +459,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase {
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
try test(Optional<Fetched>.fetchAll(db, sql, adapter: adapter))
|
||||
try test(Optional<Fetched>.fetchAll(statement, adapter: adapter))
|
||||
try test(Optional<Fetched>.fetchAll(db, SQLRequest(sql, adapter: adapter)))
|
||||
try test(SQLRequest(sql, adapter: adapter).asRequest(of: Optional<Fetched>.self).fetchAll(db))
|
||||
try test(SQLRequest<Fetched?>(sql, adapter: adapter).fetchAll(db))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -514,16 +484,14 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase {
|
||||
let sql = "SELECT throw()"
|
||||
try test(Optional<Fetched>.fetchAll(db, sql), sql: sql)
|
||||
try test(Optional<Fetched>.fetchAll(db.makeSelectStatement(sql)), sql: sql)
|
||||
try test(Optional<Fetched>.fetchAll(db, SQLRequest(sql)), sql: sql)
|
||||
try test(SQLRequest(sql).asRequest(of: Optional<Fetched>.self).fetchAll(db), sql: sql)
|
||||
try test(SQLRequest<Fetched?>(sql).fetchAll(db), sql: sql)
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT 0, throw()"
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
try test(Optional<Fetched>.fetchAll(db, sql, adapter: adapter), sql: sql)
|
||||
try test(Optional<Fetched>.fetchAll(db.makeSelectStatement(sql), adapter: adapter), sql: sql)
|
||||
try test(Optional<Fetched>.fetchAll(db, SQLRequest(sql, adapter: adapter)), sql: sql)
|
||||
try test(SQLRequest(sql, adapter: adapter).asRequest(of: Optional<Fetched>.self).fetchAll(db), sql: sql)
|
||||
try test(SQLRequest<Fetched?>(sql, adapter: adapter).fetchAll(db), sql: sql)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -546,16 +514,14 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase {
|
||||
let sql = "SELECT * FROM nonExistingTable"
|
||||
try test(Optional<Fetched>.fetchAll(db, sql), sql: sql)
|
||||
try test(Optional<Fetched>.fetchAll(db.makeSelectStatement(sql)), sql: sql)
|
||||
try test(Optional<Fetched>.fetchAll(db, SQLRequest(sql)), sql: sql)
|
||||
try test(SQLRequest(sql).asRequest(of: Optional<Fetched>.self).fetchAll(db), sql: sql)
|
||||
try test(SQLRequest<Fetched?>(sql).fetchAll(db), sql: sql)
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT * FROM nonExistingTable"
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
try test(Optional<Fetched>.fetchAll(db, sql, adapter: adapter), sql: sql)
|
||||
try test(Optional<Fetched>.fetchAll(db.makeSelectStatement(sql), adapter: adapter), sql: sql)
|
||||
try test(Optional<Fetched>.fetchAll(db, SQLRequest(sql, adapter: adapter)), sql: sql)
|
||||
try test(SQLRequest(sql, adapter: adapter).asRequest(of: Optional<Fetched>.self).fetchAll(db), sql: sql)
|
||||
try test(SQLRequest<Fetched?>(sql, adapter: adapter).fetchAll(db), sql: sql)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,139 @@
|
||||
import XCTest
|
||||
#if GRDBCIPHER
|
||||
import GRDBCipher
|
||||
#elseif GRDBCUSTOMSQLITE
|
||||
import GRDBCustomSQLite
|
||||
#else
|
||||
import GRDB
|
||||
#endif
|
||||
|
||||
class FetchRequestTests: GRDBTestCase {
|
||||
|
||||
func testRequestFetchRows() throws {
|
||||
struct CustomRequest : FetchRequest {
|
||||
typealias RowDecoder = Row
|
||||
func prepare(_ db: Database) throws -> (SelectStatement, RowAdapter?) {
|
||||
return try (db.makeSelectStatement("SELECT * FROM table1"), nil)
|
||||
}
|
||||
}
|
||||
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.create(table: "table1") { t in
|
||||
t.column("id", .integer).primaryKey()
|
||||
}
|
||||
try db.execute("INSERT INTO table1 DEFAULT VALUES")
|
||||
try db.execute("INSERT INTO table1 DEFAULT VALUES")
|
||||
|
||||
let request = CustomRequest()
|
||||
let rows = try request.fetchAll(db)
|
||||
XCTAssertEqual(lastSQLQuery, "SELECT * FROM table1")
|
||||
XCTAssertEqual(rows.count, 2)
|
||||
XCTAssertEqual(rows[0], ["id": 1])
|
||||
XCTAssertEqual(rows[1], ["id": 2])
|
||||
}
|
||||
}
|
||||
|
||||
func testRequestFetchValues() throws {
|
||||
struct CustomRequest : FetchRequest {
|
||||
typealias RowDecoder = Int
|
||||
func prepare(_ db: Database) throws -> (SelectStatement, RowAdapter?) {
|
||||
return try (db.makeSelectStatement("SELECT id FROM table1"), nil)
|
||||
}
|
||||
}
|
||||
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.create(table: "table1") { t in
|
||||
t.column("id", .integer).primaryKey()
|
||||
}
|
||||
try db.execute("INSERT INTO table1 DEFAULT VALUES")
|
||||
try db.execute("INSERT INTO table1 DEFAULT VALUES")
|
||||
|
||||
let request = CustomRequest()
|
||||
let ints = try request.fetchAll(db)
|
||||
XCTAssertEqual(lastSQLQuery, "SELECT id FROM table1")
|
||||
XCTAssertEqual(ints.count, 2)
|
||||
XCTAssertEqual(ints[0], 1)
|
||||
XCTAssertEqual(ints[1], 2)
|
||||
}
|
||||
}
|
||||
|
||||
func testRequestFetchRecords() throws {
|
||||
struct CustomRecord: RowConvertible, Decodable {
|
||||
var id: Int
|
||||
}
|
||||
struct CustomRequest : FetchRequest {
|
||||
typealias RowDecoder = CustomRecord
|
||||
func prepare(_ db: Database) throws -> (SelectStatement, RowAdapter?) {
|
||||
return try (db.makeSelectStatement("SELECT id FROM table1"), nil)
|
||||
}
|
||||
}
|
||||
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.create(table: "table1") { t in
|
||||
t.column("id", .integer).primaryKey()
|
||||
}
|
||||
try db.execute("INSERT INTO table1 DEFAULT VALUES")
|
||||
try db.execute("INSERT INTO table1 DEFAULT VALUES")
|
||||
|
||||
let request = CustomRequest()
|
||||
let records = try request.fetchAll(db)
|
||||
XCTAssertEqual(lastSQLQuery, "SELECT id FROM table1")
|
||||
XCTAssertEqual(records.count, 2)
|
||||
XCTAssertEqual(records[0].id, 1)
|
||||
XCTAssertEqual(records[1].id, 2)
|
||||
}
|
||||
}
|
||||
|
||||
func testRequestFetchCount() throws {
|
||||
struct CustomRequest : FetchRequest {
|
||||
typealias RowDecoder = Row
|
||||
func prepare(_ db: Database) throws -> (SelectStatement, RowAdapter?) {
|
||||
return try (db.makeSelectStatement("SELECT * FROM table1"), nil)
|
||||
}
|
||||
}
|
||||
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.create(table: "table1") { t in
|
||||
t.column("id", .integer).primaryKey()
|
||||
}
|
||||
try db.execute("INSERT INTO table1 DEFAULT VALUES")
|
||||
try db.execute("INSERT INTO table1 DEFAULT VALUES")
|
||||
|
||||
let request = CustomRequest()
|
||||
let count = try request.fetchCount(db)
|
||||
XCTAssertEqual(lastSQLQuery, "SELECT COUNT(*) FROM (SELECT * FROM table1)")
|
||||
XCTAssertEqual(count, 2)
|
||||
}
|
||||
}
|
||||
|
||||
func testRequestCustomizedFetchCount() throws {
|
||||
struct CustomRequest : FetchRequest {
|
||||
typealias RowDecoder = Row
|
||||
func prepare(_ db: Database) throws -> (SelectStatement, RowAdapter?) {
|
||||
return try (db.makeSelectStatement("INVALID"), nil)
|
||||
}
|
||||
|
||||
func fetchCount(_ db: Database) throws -> Int {
|
||||
return 2
|
||||
}
|
||||
}
|
||||
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.create(table: "table1") { t in
|
||||
t.column("id", .integer).primaryKey()
|
||||
}
|
||||
try db.execute("INSERT INTO table1 DEFAULT VALUES")
|
||||
try db.execute("INSERT INTO table1 DEFAULT VALUES")
|
||||
|
||||
let request = CustomRequest()
|
||||
let count = try request.fetchCount(db)
|
||||
XCTAssertEqual(lastSQLQuery, "INSERT INTO table1 DEFAULT VALUES")
|
||||
XCTAssertEqual(count, 2)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -145,21 +145,23 @@ class GRDBTestCase: XCTestCase {
|
||||
}
|
||||
|
||||
// Compare SQL strings (ignoring leading and trailing white space and semicolons.
|
||||
func assertEqualSQL(_ db: Database, _ request: Request, _ sql: String, file: StaticString = #file, line: UInt = #line) throws {
|
||||
_ = try Row.fetchOne(db, request)
|
||||
func assertEqualSQL<Request: FetchRequest>(_ db: Database, _ request: Request, _ sql: String, file: StaticString = #file, line: UInt = #line) throws {
|
||||
let (statement, _) = try request.prepare(db)
|
||||
try statement.cursor().next()
|
||||
assertEqualSQL(lastSQLQuery, sql, file: file, line: line)
|
||||
}
|
||||
|
||||
// Compare SQL strings (ignoring leading and trailing white space and semicolons.
|
||||
func assertEqualSQL(_ databaseReader: DatabaseReader, _ request: Request, _ sql: String, file: StaticString = #file, line: UInt = #line) throws {
|
||||
func assertEqualSQL<Request: FetchRequest>(_ databaseReader: DatabaseReader, _ request: Request, _ sql: String, file: StaticString = #file, line: UInt = #line) throws {
|
||||
try databaseReader.unsafeRead { db in
|
||||
try assertEqualSQL(db, request, sql, file: file, line: line)
|
||||
}
|
||||
}
|
||||
|
||||
func sql(_ databaseReader: DatabaseReader, _ request: Request) -> String {
|
||||
func sql<Request: FetchRequest>(_ databaseReader: DatabaseReader, _ request: Request) -> String {
|
||||
return try! databaseReader.unsafeRead { db in
|
||||
_ = try Row.fetchOne(db, request)
|
||||
let (statement, _) = try request.prepare(db)
|
||||
try statement.cursor().next()
|
||||
return lastSQLQuery
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,8 +98,8 @@ private struct FlatModel: RowConvertible {
|
||||
self.t5count = row.scoped(on: Scopes.suffix)!["t5count"]
|
||||
}
|
||||
|
||||
static func all() -> AnyTypedRequest<FlatModel> {
|
||||
return SQLRequest(testedSQL).adapted { db in
|
||||
static func all() -> AdaptedFetchRequest<SQLRequest<FlatModel>> {
|
||||
return SQLRequest<FlatModel>(testedSQL).adapted { db in
|
||||
let adapters = try splittingRowAdapters(columnCounts: [
|
||||
T1.numberOfSelectedColumns(db),
|
||||
T2.numberOfSelectedColumns(db),
|
||||
@@ -111,8 +111,7 @@ private struct FlatModel: RowConvertible {
|
||||
Scopes.t2Right: adapters[2],
|
||||
Scopes.t3: adapters[3],
|
||||
Scopes.suffix: adapters[4]]) // The only test for adapters[4]
|
||||
}
|
||||
.asRequest(of: FlatModel.self)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,8 +122,8 @@ private struct CodableFlatModel: RowConvertible, Codable {
|
||||
var t3: T3?
|
||||
var t5count: Int
|
||||
|
||||
static func all() -> AnyTypedRequest<CodableFlatModel> {
|
||||
return SQLRequest(testedSQL).adapted { db in
|
||||
static func all() -> AdaptedFetchRequest<SQLRequest<CodableFlatModel>> {
|
||||
return SQLRequest<CodableFlatModel>(testedSQL).adapted { db in
|
||||
let adapters = try splittingRowAdapters(columnCounts: [
|
||||
T1.numberOfSelectedColumns(db),
|
||||
T2.numberOfSelectedColumns(db),
|
||||
@@ -135,8 +134,7 @@ private struct CodableFlatModel: RowConvertible, Codable {
|
||||
CodingKeys.t2Left.stringValue: adapters[1],
|
||||
CodingKeys.t2Right.stringValue: adapters[2],
|
||||
CodingKeys.t3.stringValue: adapters[3]])
|
||||
}
|
||||
.asRequest(of: CodableFlatModel.self)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -151,8 +149,8 @@ private struct CodableNestedModel: RowConvertible, Codable {
|
||||
var t3: T3?
|
||||
var t5count: Int
|
||||
|
||||
static func all() -> AnyTypedRequest<CodableNestedModel> {
|
||||
return SQLRequest(testedSQL).adapted { db in
|
||||
static func all() -> AdaptedFetchRequest<SQLRequest<CodableNestedModel>> {
|
||||
return SQLRequest<CodableNestedModel>(testedSQL).adapted { db in
|
||||
let adapters = try splittingRowAdapters(columnCounts: [
|
||||
T1.numberOfSelectedColumns(db),
|
||||
T2.numberOfSelectedColumns(db),
|
||||
@@ -167,8 +165,7 @@ private struct CodableNestedModel: RowConvertible, Codable {
|
||||
"left": adapters[1],
|
||||
"right": adapters[2]]),
|
||||
CodingKeys.t3.stringValue: adapters[3]])
|
||||
}
|
||||
.asRequest(of: CodableNestedModel.self)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -274,7 +271,7 @@ class JoinSupportTests: GRDBTestCase {
|
||||
func testSplittingRowAdapters() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
let request = SQLRequest(testedSQL).adapted { db in
|
||||
let request = SQLRequest<Row>(testedSQL).adapted { db in
|
||||
let adapters = try splittingRowAdapters(columnCounts: [
|
||||
T1.numberOfSelectedColumns(db),
|
||||
T2.numberOfSelectedColumns(db),
|
||||
@@ -288,7 +285,7 @@ class JoinSupportTests: GRDBTestCase {
|
||||
"t3": adapters[3],
|
||||
"suffix": adapters[4]])
|
||||
}
|
||||
let rows = try Row.fetchAll(db, request)
|
||||
let rows = try request.fetchAll(db)
|
||||
XCTAssertEqual(rows.count, 3)
|
||||
|
||||
XCTAssertEqual(rows[0].unscoped, [
|
||||
|
||||
@@ -68,7 +68,7 @@ class QueryInterfaceExtensibilityTests: GRDBTestCase {
|
||||
try db.execute("INSERT INTO records (date) VALUES (?)", arguments: [date])
|
||||
|
||||
let request = Record.select(strftime("%Y", Column("date")))
|
||||
let year = try Int.fetchOne(db, request)
|
||||
let year = try request.asRequest(of: Int.self).fetchOne(db)
|
||||
XCTAssertEqual(year, 1970)
|
||||
XCTAssertEqual(self.lastSQLQuery, "SELECT STRFTIME('%Y', \"date\") FROM \"records\"")
|
||||
}
|
||||
@@ -105,7 +105,7 @@ class QueryInterfaceExtensibilityTests: GRDBTestCase {
|
||||
try db.execute("INSERT INTO records (text) VALUES (?)", arguments: ["foo"])
|
||||
|
||||
let request = Record.select(cast(Column("text"), as: .blob))
|
||||
let dbValue = try DatabaseValue.fetchOne(db, request)!
|
||||
let dbValue = try request.asRequest(of: DatabaseValue.self).fetchOne(db)!
|
||||
switch dbValue.storage {
|
||||
case .blob:
|
||||
break
|
||||
|
||||
@@ -51,7 +51,7 @@ class QueryInterfaceRequestTests: GRDBTestCase {
|
||||
try db.execute("INSERT INTO readers (name, age) VALUES (?, ?)", arguments: ["Barbara", 36])
|
||||
|
||||
do {
|
||||
let rows = try Row.fetchAll(db, tableRequest)
|
||||
let rows = try tableRequest.asRequest(of: Row.self).fetchAll(db)
|
||||
XCTAssertEqual(lastSQLQuery, "SELECT * FROM \"readers\"")
|
||||
XCTAssertEqual(rows.count, 2)
|
||||
XCTAssertEqual(rows[0]["id"] as Int64, 1)
|
||||
@@ -63,7 +63,7 @@ class QueryInterfaceRequestTests: GRDBTestCase {
|
||||
}
|
||||
|
||||
do {
|
||||
let row = try Row.fetchOne(db, tableRequest)!
|
||||
let row = try tableRequest.asRequest(of: Row.self).fetchOne(db)!
|
||||
XCTAssertEqual(lastSQLQuery, "SELECT * FROM \"readers\"")
|
||||
XCTAssertEqual(row["id"] as Int64, 1)
|
||||
XCTAssertEqual(row["name"] as String, "Arthur")
|
||||
@@ -72,7 +72,7 @@ class QueryInterfaceRequestTests: GRDBTestCase {
|
||||
|
||||
do {
|
||||
var names: [String] = []
|
||||
let rows = try Row.fetchCursor(db, tableRequest)
|
||||
let rows = try tableRequest.asRequest(of: Row.self).fetchCursor(db)
|
||||
while let row = try rows.next() {
|
||||
names.append(row["name"])
|
||||
}
|
||||
@@ -139,7 +139,7 @@ class QueryInterfaceRequestTests: GRDBTestCase {
|
||||
try db.execute("INSERT INTO readers (name, age) VALUES (?, ?)", arguments: ["Barbara", 36])
|
||||
|
||||
let request = tableRequest.select(sql: "name, id - 1")
|
||||
let rows = try Row.fetchAll(db, request)
|
||||
let rows = try request.asRequest(of: Row.self).fetchAll(db)
|
||||
XCTAssertEqual(lastSQLQuery, "SELECT name, id - 1 FROM \"readers\"")
|
||||
XCTAssertEqual(rows.count, 2)
|
||||
XCTAssertEqual(rows[0][0] as String, "Arthur")
|
||||
@@ -156,7 +156,7 @@ class QueryInterfaceRequestTests: GRDBTestCase {
|
||||
try db.execute("INSERT INTO readers (name, age) VALUES (?, ?)", arguments: ["Barbara", 36])
|
||||
|
||||
let request = tableRequest.select(sql: "name, id - ?", arguments: [1])
|
||||
let rows = try Row.fetchAll(db, request)
|
||||
let rows = try request.asRequest(of: Row.self).fetchAll(db)
|
||||
XCTAssertEqual(lastSQLQuery, "SELECT name, id - 1 FROM \"readers\"")
|
||||
XCTAssertEqual(rows.count, 2)
|
||||
XCTAssertEqual(rows[0][0] as String, "Arthur")
|
||||
@@ -173,7 +173,7 @@ class QueryInterfaceRequestTests: GRDBTestCase {
|
||||
try db.execute("INSERT INTO readers (name, age) VALUES (?, ?)", arguments: ["Barbara", 36])
|
||||
|
||||
let request = tableRequest.select(sql: "name, id - :n", arguments: ["n": 1])
|
||||
let rows = try Row.fetchAll(db, request)
|
||||
let rows = try request.asRequest(of: Row.self).fetchAll(db)
|
||||
XCTAssertEqual(lastSQLQuery, "SELECT name, id - 1 FROM \"readers\"")
|
||||
XCTAssertEqual(rows.count, 2)
|
||||
XCTAssertEqual(rows[0][0] as String, "Arthur")
|
||||
@@ -190,7 +190,7 @@ class QueryInterfaceRequestTests: GRDBTestCase {
|
||||
try db.execute("INSERT INTO readers (name, age) VALUES (?, ?)", arguments: ["Barbara", 36])
|
||||
|
||||
let request = tableRequest.select(Col.name, Col.id - 1)
|
||||
let rows = try Row.fetchAll(db, request)
|
||||
let rows = try request.asRequest(of: Row.self).fetchAll(db)
|
||||
XCTAssertEqual(lastSQLQuery, "SELECT \"name\", (\"id\" - 1) FROM \"readers\"")
|
||||
XCTAssertEqual(rows.count, 2)
|
||||
XCTAssertEqual(rows[0][0] as String, "Arthur")
|
||||
@@ -206,7 +206,7 @@ class QueryInterfaceRequestTests: GRDBTestCase {
|
||||
try db.execute("INSERT INTO readers (name, age) VALUES (?, ?)", arguments: ["Arthur", 42])
|
||||
|
||||
let request = tableRequest.select(Col.name.aliased("nom"), (Col.age + 1).aliased("agePlusOne"))
|
||||
let row = try Row.fetchOne(db, request)!
|
||||
let row = try request.asRequest(of: Row.self).fetchOne(db)!
|
||||
XCTAssertEqual(lastSQLQuery, "SELECT \"name\" AS \"nom\", (\"age\" + 1) AS \"agePlusOne\" FROM \"readers\"")
|
||||
XCTAssertEqual(row["nom"] as String, "Arthur")
|
||||
XCTAssertEqual(row["agePlusOne"] as Int, 43)
|
||||
|
||||
@@ -1,83 +0,0 @@
|
||||
import XCTest
|
||||
#if GRDBCIPHER
|
||||
import GRDBCipher
|
||||
#elseif GRDBCUSTOMSQLITE
|
||||
import GRDBCustomSQLite
|
||||
#else
|
||||
import GRDB
|
||||
#endif
|
||||
|
||||
class RequestTests: GRDBTestCase {
|
||||
|
||||
func testRequestFetch() throws {
|
||||
struct CustomRequest : Request {
|
||||
func prepare(_ db: Database) throws -> (SelectStatement, RowAdapter?) {
|
||||
return try (db.makeSelectStatement("SELECT * FROM table1"), nil)
|
||||
}
|
||||
}
|
||||
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.create(table: "table1") { t in
|
||||
t.column("id", .integer).primaryKey()
|
||||
}
|
||||
try db.execute("INSERT INTO table1 DEFAULT VALUES")
|
||||
try db.execute("INSERT INTO table1 DEFAULT VALUES")
|
||||
|
||||
let request: Request = CustomRequest() // Lose type
|
||||
let rows = try Row.fetchAll(db, request)
|
||||
XCTAssertEqual(lastSQLQuery, "SELECT * FROM table1")
|
||||
XCTAssertEqual(rows.count, 2)
|
||||
XCTAssertEqual(rows[0], ["id": 1])
|
||||
XCTAssertEqual(rows[1], ["id": 2])
|
||||
}
|
||||
}
|
||||
|
||||
func testRequestFetchCount() throws {
|
||||
struct CustomRequest : Request {
|
||||
func prepare(_ db: Database) throws -> (SelectStatement, RowAdapter?) {
|
||||
return try (db.makeSelectStatement("SELECT * FROM table1"), nil)
|
||||
}
|
||||
}
|
||||
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.create(table: "table1") { t in
|
||||
t.column("id", .integer).primaryKey()
|
||||
}
|
||||
try db.execute("INSERT INTO table1 DEFAULT VALUES")
|
||||
try db.execute("INSERT INTO table1 DEFAULT VALUES")
|
||||
|
||||
let request: Request = CustomRequest() // Lose type
|
||||
let count = try request.fetchCount(db)
|
||||
XCTAssertEqual(lastSQLQuery, "SELECT COUNT(*) FROM (SELECT * FROM table1)")
|
||||
XCTAssertEqual(count, 2)
|
||||
}
|
||||
}
|
||||
|
||||
func testRequestCustomizedFetchCount() throws {
|
||||
struct CustomRequest : Request {
|
||||
func prepare(_ db: Database) throws -> (SelectStatement, RowAdapter?) {
|
||||
return try (db.makeSelectStatement("INVALID"), nil)
|
||||
}
|
||||
|
||||
func fetchCount(_ db: Database) throws -> Int {
|
||||
return 2
|
||||
}
|
||||
}
|
||||
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.create(table: "table1") { t in
|
||||
t.column("id", .integer).primaryKey()
|
||||
}
|
||||
try db.execute("INSERT INTO table1 DEFAULT VALUES")
|
||||
try db.execute("INSERT INTO table1 DEFAULT VALUES")
|
||||
|
||||
let request: Request = CustomRequest() // Lose type
|
||||
let count = try request.fetchCount(db)
|
||||
XCTAssertEqual(lastSQLQuery, "INSERT INTO table1 DEFAULT VALUES")
|
||||
XCTAssertEqual(count, 2)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -676,71 +676,38 @@ class AdapterRowTests : RowTestCase {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
do {
|
||||
let row = try SQLRequest("SELECT 0 AS a0, 1 AS a1, 2 AS a2", adapter: SuffixRowAdapter(fromIndex: 1))
|
||||
.asRequest(of: Row.self)
|
||||
let row = try SQLRequest<Row>("SELECT 0 AS a0, 1 AS a1, 2 AS a2", adapter: SuffixRowAdapter(fromIndex: 1))
|
||||
.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")
|
||||
let row = try SQLRequest<Row>("SELECT 0 AS a0, 1 AS a1, 2 AS a2")
|
||||
.adapted { _ in SuffixRowAdapter(fromIndex: 1) }
|
||||
.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", adapter: SuffixRowAdapter(fromIndex: 1))
|
||||
let row = try SQLRequest<Row>("SELECT 0 AS a0, 1 AS a1, 2 AS a2", adapter: SuffixRowAdapter(fromIndex: 1))
|
||||
.adapted { _ in SuffixRowAdapter(fromIndex: 1) }
|
||||
.asRequest(of: Row.self)
|
||||
.fetchOne(db)!
|
||||
XCTAssertEqual(Array(row.columnNames), ["a2"])
|
||||
XCTAssertEqual(Array(row.databaseValues), [2.databaseValue])
|
||||
}
|
||||
do {
|
||||
let row = try SQLRequest("SELECT 0 AS a0", adapter: ColumnMapping(["a1": "a0"]))
|
||||
let row = try SQLRequest<Row>("SELECT 0 AS a0", adapter: ColumnMapping(["a1": "a0"]))
|
||||
.adapted { _ in ColumnMapping(["a2": "a1"]) }
|
||||
.asRequest(of: Row.self)
|
||||
.fetchOne(db)!
|
||||
XCTAssertEqual(Array(row.columnNames), ["a2"])
|
||||
XCTAssertEqual(Array(row.databaseValues), [0.databaseValue])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testTypedRequestAdapter() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
do {
|
||||
let row = try SQLRequest("SELECT 0 AS a0, 1 AS a1, 2 AS a2", adapter: SuffixRowAdapter(fromIndex: 1))
|
||||
.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")
|
||||
.asRequest(of: Row.self)
|
||||
.adapted { _ in SuffixRowAdapter(fromIndex: 1) }
|
||||
.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", adapter: SuffixRowAdapter(fromIndex: 1))
|
||||
.asRequest(of: Row.self)
|
||||
.adapted { _ in SuffixRowAdapter(fromIndex: 1) }
|
||||
.fetchOne(db)!
|
||||
XCTAssertEqual(Array(row.columnNames), ["a2"])
|
||||
XCTAssertEqual(Array(row.databaseValues), [2.databaseValue])
|
||||
}
|
||||
do {
|
||||
let row = try SQLRequest("SELECT 0 AS a0", adapter: ColumnMapping(["a1": "a0"]))
|
||||
.asRequest(of: Row.self)
|
||||
let row = try SQLRequest<Row>("SELECT 0 AS a0", adapter: ColumnMapping(["a1": "a0"]))
|
||||
.adapted { _ in ColumnMapping(["a2": "a1"]) }
|
||||
.adapted { _ in ColumnMapping(["a3": "a2"]) }
|
||||
.fetchOne(db)!
|
||||
XCTAssertEqual(Array(row.columnNames), ["a2"])
|
||||
XCTAssertEqual(Array(row.columnNames), ["a3"])
|
||||
XCTAssertEqual(Array(row.databaseValues), [0.databaseValue])
|
||||
}
|
||||
}
|
||||
|
||||
@@ -158,7 +158,7 @@ class RowConvertibleQueryInterfaceRequestTests: GRDBTestCase {
|
||||
let request = Reader.all()
|
||||
|
||||
do {
|
||||
let readers = try AltReader.fetchAll(db, request)
|
||||
let readers = try request.asRequest(of: AltReader.self).fetchAll(db)
|
||||
XCTAssertEqual(lastSQLQuery, "SELECT * FROM \"readers\"")
|
||||
XCTAssertEqual(readers.count, 2)
|
||||
XCTAssertEqual(readers[0].id!, arthur.id!)
|
||||
@@ -170,7 +170,7 @@ class RowConvertibleQueryInterfaceRequestTests: GRDBTestCase {
|
||||
}
|
||||
|
||||
do {
|
||||
let reader = try AltReader.fetchOne(db, request)!
|
||||
let reader = try request.asRequest(of: AltReader.self).fetchOne(db)!
|
||||
XCTAssertEqual(lastSQLQuery, "SELECT * FROM \"readers\"")
|
||||
XCTAssertEqual(reader.id!, arthur.id!)
|
||||
XCTAssertEqual(reader.name, arthur.name)
|
||||
@@ -178,7 +178,7 @@ class RowConvertibleQueryInterfaceRequestTests: GRDBTestCase {
|
||||
}
|
||||
|
||||
do {
|
||||
let names = try AltReader.fetchCursor(db, request).map { $0.name }
|
||||
let names = try request.asRequest(of: AltReader.self).fetchCursor(db).map { $0.name }
|
||||
XCTAssertEqual(lastSQLQuery, "SELECT * FROM \"readers\"")
|
||||
XCTAssertEqual(try names.next()!, arthur.name)
|
||||
XCTAssertEqual(try names.next()!, barbara.name)
|
||||
|
||||
@@ -45,8 +45,7 @@ class RowConvertibleTests: GRDBTestCase {
|
||||
let statement = try db.makeSelectStatement(sql)
|
||||
try test(Fetched.fetchCursor(db, sql))
|
||||
try test(Fetched.fetchCursor(statement))
|
||||
try test(Fetched.fetchCursor(db, SQLRequest(sql)))
|
||||
try test(SQLRequest(sql).asRequest(of: Fetched.self).fetchCursor(db))
|
||||
try test(SQLRequest<Fetched>(sql).fetchCursor(db))
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT 0 AS firstName, 'Arthur' AS firstName, 'Martin' AS lastName UNION ALL SELECT 0, 'Barbara', 'Gourde'"
|
||||
@@ -54,8 +53,7 @@ class RowConvertibleTests: GRDBTestCase {
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
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).asRequest(of: Fetched.self).fetchCursor(db))
|
||||
try test(SQLRequest<Fetched>(sql, adapter: adapter).fetchCursor(db))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -89,16 +87,14 @@ class RowConvertibleTests: GRDBTestCase {
|
||||
let sql = "SELECT throw(), NULL"
|
||||
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).asRequest(of: Fetched.self).fetchCursor(db), sql: sql)
|
||||
try test(SQLRequest<Fetched>(sql).fetchCursor(db), sql: sql)
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT 0, throw(), NULL"
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
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).asRequest(of: Fetched.self).fetchCursor(db), sql: sql)
|
||||
try test(SQLRequest<Fetched>(sql, adapter: adapter).fetchCursor(db), sql: sql)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -121,16 +117,14 @@ class RowConvertibleTests: GRDBTestCase {
|
||||
let sql = "SELECT * FROM nonExistingTable"
|
||||
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).asRequest(of: Fetched.self).fetchCursor(db), sql: sql)
|
||||
try test(SQLRequest<Fetched>(sql).fetchCursor(db), sql: sql)
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT * FROM nonExistingTable"
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
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).asRequest(of: Fetched.self).fetchCursor(db), sql: sql)
|
||||
try test(SQLRequest<Fetched>(sql, adapter: adapter).fetchCursor(db), sql: sql)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -147,8 +141,7 @@ class RowConvertibleTests: GRDBTestCase {
|
||||
let statement = try db.makeSelectStatement(sql)
|
||||
try test(Fetched.fetchAll(db, sql))
|
||||
try test(Fetched.fetchAll(statement))
|
||||
try test(Fetched.fetchAll(db, SQLRequest(sql)))
|
||||
try test(SQLRequest(sql).asRequest(of: Fetched.self).fetchAll(db))
|
||||
try test(SQLRequest<Fetched>(sql).fetchAll(db))
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT 0 AS firstName, 'Arthur' AS firstName, 'Martin' AS lastName UNION ALL SELECT 0, 'Barbara', 'Gourde'"
|
||||
@@ -156,8 +149,7 @@ class RowConvertibleTests: GRDBTestCase {
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
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).asRequest(of: Fetched.self).fetchAll(db))
|
||||
try test(SQLRequest<Fetched>(sql, adapter: adapter).fetchAll(db))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -182,16 +174,14 @@ class RowConvertibleTests: GRDBTestCase {
|
||||
let sql = "SELECT throw()"
|
||||
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).asRequest(of: Fetched.self).fetchAll(db), sql: sql)
|
||||
try test(SQLRequest<Fetched>(sql).fetchAll(db), sql: sql)
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT 0, throw()"
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
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).asRequest(of: Fetched.self).fetchAll(db), sql: sql)
|
||||
try test(SQLRequest<Fetched>(sql, adapter: adapter).fetchAll(db), sql: sql)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -214,16 +204,14 @@ class RowConvertibleTests: GRDBTestCase {
|
||||
let sql = "SELECT * FROM nonExistingTable"
|
||||
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).asRequest(of: Fetched.self).fetchAll(db), sql: sql)
|
||||
try test(SQLRequest<Fetched>(sql).fetchAll(db), sql: sql)
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT * FROM nonExistingTable"
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
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).asRequest(of: Fetched.self).fetchAll(db), sql: sql)
|
||||
try test(SQLRequest<Fetched>(sql, adapter: adapter).fetchAll(db), sql: sql)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -240,8 +228,7 @@ class RowConvertibleTests: GRDBTestCase {
|
||||
let statement = try db.makeSelectStatement(sql)
|
||||
try test(Fetched.fetchOne(db, sql))
|
||||
try test(Fetched.fetchOne(statement))
|
||||
try test(Fetched.fetchOne(db, SQLRequest(sql)))
|
||||
try test(SQLRequest(sql).asRequest(of: Fetched.self).fetchOne(db))
|
||||
try test(SQLRequest<Fetched>(sql).fetchOne(db))
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT 0, 1 WHERE 0"
|
||||
@@ -249,8 +236,7 @@ class RowConvertibleTests: GRDBTestCase {
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
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).asRequest(of: Fetched.self).fetchOne(db))
|
||||
try test(SQLRequest<Fetched>(sql, adapter: adapter).fetchOne(db))
|
||||
}
|
||||
}
|
||||
do {
|
||||
@@ -263,8 +249,7 @@ class RowConvertibleTests: GRDBTestCase {
|
||||
let statement = try db.makeSelectStatement(sql)
|
||||
try test(Fetched.fetchOne(db, sql))
|
||||
try test(Fetched.fetchOne(statement))
|
||||
try test(Fetched.fetchOne(db, SQLRequest(sql)))
|
||||
try test(SQLRequest(sql).asRequest(of: Fetched.self).fetchOne(db))
|
||||
try test(SQLRequest<Fetched>(sql).fetchOne(db))
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT 0 AS firstName, 'Arthur' AS firstName, 'Martin' AS lastName"
|
||||
@@ -272,8 +257,7 @@ class RowConvertibleTests: GRDBTestCase {
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
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).asRequest(of: Fetched.self).fetchOne(db))
|
||||
try test(SQLRequest<Fetched>(sql, adapter: adapter).fetchOne(db))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -299,16 +283,14 @@ class RowConvertibleTests: GRDBTestCase {
|
||||
let sql = "SELECT throw()"
|
||||
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).asRequest(of: Fetched.self).fetchOne(db), sql: sql)
|
||||
try test(SQLRequest<Fetched>(sql).fetchOne(db), sql: sql)
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT 0, throw()"
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
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).asRequest(of: Fetched.self).fetchOne(db), sql: sql)
|
||||
try test(SQLRequest<Fetched>(sql, adapter: adapter).fetchOne(db), sql: sql)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -331,16 +313,14 @@ class RowConvertibleTests: GRDBTestCase {
|
||||
let sql = "SELECT * FROM nonExistingTable"
|
||||
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).asRequest(of: Fetched.self).fetchOne(db), sql: sql)
|
||||
try test(SQLRequest<Fetched>(sql).fetchOne(db), sql: sql)
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT * FROM nonExistingTable"
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
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).asRequest(of: Fetched.self).fetchOne(db), sql: sql)
|
||||
try test(SQLRequest<Fetched>(sql, adapter: adapter).fetchOne(db), sql: sql)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,8 +34,7 @@ class RowFetchTests: GRDBTestCase {
|
||||
let statement = try db.makeSelectStatement(sql)
|
||||
try test(Row.fetchCursor(db, sql))
|
||||
try test(Row.fetchCursor(statement))
|
||||
try test(Row.fetchCursor(db, SQLRequest(sql)))
|
||||
try test(SQLRequest(sql).asRequest(of: Row.self).fetchCursor(db))
|
||||
try test(SQLRequest<Row>(sql).fetchCursor(db))
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT 0 AS firstName, 'Arthur' AS firstName, 'Martin' AS lastName UNION ALL SELECT 0, 'Barbara', 'Gourde'"
|
||||
@@ -43,8 +42,7 @@ class RowFetchTests: GRDBTestCase {
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
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).asRequest(of: Row.self).fetchCursor(db))
|
||||
try test(SQLRequest<Row>(sql, adapter: adapter).fetchCursor(db))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -78,16 +76,14 @@ class RowFetchTests: GRDBTestCase {
|
||||
let sql = "SELECT throw(), NULL"
|
||||
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).asRequest(of: Row.self).fetchCursor(db), sql: sql)
|
||||
try test(SQLRequest<Row>(sql).fetchCursor(db), sql: sql)
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT 0, throw(), NULL"
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
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).asRequest(of: Row.self).fetchCursor(db), sql: sql)
|
||||
try test(SQLRequest<Row>(sql, adapter: adapter).fetchCursor(db), sql: sql)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -110,16 +106,14 @@ class RowFetchTests: GRDBTestCase {
|
||||
let sql = "SELECT * FROM nonExistingTable"
|
||||
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).asRequest(of: Row.self).fetchCursor(db), sql: sql)
|
||||
try test(SQLRequest<Row>(sql).fetchCursor(db), sql: sql)
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT * FROM nonExistingTable"
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
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).asRequest(of: Row.self).fetchCursor(db), sql: sql)
|
||||
try test(SQLRequest<Row>(sql, adapter: adapter).fetchCursor(db), sql: sql)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -136,8 +130,7 @@ class RowFetchTests: GRDBTestCase {
|
||||
let statement = try db.makeSelectStatement(sql)
|
||||
try test(Row.fetchAll(db, sql))
|
||||
try test(Row.fetchAll(statement))
|
||||
try test(Row.fetchAll(db, SQLRequest(sql)))
|
||||
try test(SQLRequest(sql).asRequest(of: Row.self).fetchAll(db))
|
||||
try test(SQLRequest<Row>(sql).fetchAll(db))
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT 0 AS firstName, 'Arthur' AS firstName, 'Martin' AS lastName UNION ALL SELECT 0, 'Barbara', 'Gourde'"
|
||||
@@ -145,8 +138,7 @@ class RowFetchTests: GRDBTestCase {
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
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).asRequest(of: Row.self).fetchAll(db))
|
||||
try test(SQLRequest<Row>(sql, adapter: adapter).fetchAll(db))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -171,16 +163,14 @@ class RowFetchTests: GRDBTestCase {
|
||||
let sql = "SELECT throw()"
|
||||
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).asRequest(of: Row.self).fetchAll(db), sql: sql)
|
||||
try test(SQLRequest<Row>(sql).fetchAll(db), sql: sql)
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT 0, throw()"
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
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).asRequest(of: Row.self).fetchAll(db), sql: sql)
|
||||
try test(SQLRequest<Row>(sql, adapter: adapter).fetchAll(db), sql: sql)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -203,16 +193,14 @@ class RowFetchTests: GRDBTestCase {
|
||||
let sql = "SELECT * FROM nonExistingTable"
|
||||
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).asRequest(of: Row.self).fetchAll(db), sql: sql)
|
||||
try test(SQLRequest<Row>(sql).fetchAll(db), sql: sql)
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT * FROM nonExistingTable"
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
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).asRequest(of: Row.self).fetchAll(db), sql: sql)
|
||||
try test(SQLRequest<Row>(sql, adapter: adapter).fetchAll(db), sql: sql)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -229,8 +217,7 @@ class RowFetchTests: GRDBTestCase {
|
||||
let statement = try db.makeSelectStatement(sql)
|
||||
try test(Row.fetchOne(db, sql))
|
||||
try test(Row.fetchOne(statement))
|
||||
try test(Row.fetchOne(db, SQLRequest(sql)))
|
||||
try test(SQLRequest(sql).asRequest(of: Row.self).fetchOne(db))
|
||||
try test(SQLRequest<Row>(sql).fetchOne(db))
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT 0, 1 WHERE 0"
|
||||
@@ -238,8 +225,7 @@ class RowFetchTests: GRDBTestCase {
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
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).asRequest(of: Row.self).fetchOne(db))
|
||||
try test(SQLRequest<Row>(sql, adapter: adapter).fetchOne(db))
|
||||
}
|
||||
}
|
||||
do {
|
||||
@@ -252,8 +238,7 @@ class RowFetchTests: GRDBTestCase {
|
||||
let statement = try db.makeSelectStatement(sql)
|
||||
try test(Row.fetchOne(db, sql))
|
||||
try test(Row.fetchOne(statement))
|
||||
try test(Row.fetchOne(db, SQLRequest(sql)))
|
||||
try test(SQLRequest(sql).asRequest(of: Row.self).fetchOne(db))
|
||||
try test(SQLRequest<Row>(sql).fetchOne(db))
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT 0 AS firstName, 'Arthur' AS firstName, 'Martin' AS lastName"
|
||||
@@ -261,8 +246,7 @@ class RowFetchTests: GRDBTestCase {
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
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).asRequest(of: Row.self).fetchOne(db))
|
||||
try test(SQLRequest<Row>(sql, adapter: adapter).fetchOne(db))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -288,16 +272,14 @@ class RowFetchTests: GRDBTestCase {
|
||||
let sql = "SELECT throw()"
|
||||
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).asRequest(of: Row.self).fetchOne(db), sql: sql)
|
||||
try test(SQLRequest<Row>(sql).fetchOne(db), sql: sql)
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT 0, throw()"
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
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).asRequest(of: Row.self).fetchOne(db), sql: sql)
|
||||
try test(SQLRequest<Row>(sql, adapter: adapter).fetchOne(db), sql: sql)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -320,16 +302,14 @@ class RowFetchTests: GRDBTestCase {
|
||||
let sql = "SELECT * FROM nonExistingTable"
|
||||
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).asRequest(of: Row.self).fetchOne(db), sql: sql)
|
||||
try test(SQLRequest<Row>(sql).fetchOne(db), sql: sql)
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT * FROM nonExistingTable"
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
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).asRequest(of: Row.self).fetchOne(db), sql: sql)
|
||||
try test(SQLRequest<Row>(sql, adapter: adapter).fetchOne(db), sql: sql)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,21 +12,23 @@ class SQLRequestTests: GRDBTestCase {
|
||||
func testSQLRequest() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
let request = SQLRequest("SELECT 1")
|
||||
let request = SQLRequest<Row>("SELECT 1")
|
||||
let (statement, adapter) = try request.prepare(db)
|
||||
XCTAssertEqual(statement.sql, "SELECT 1")
|
||||
XCTAssertNil(adapter)
|
||||
let row = try request.fetchOne(db)
|
||||
XCTAssertEqual(row, ["1": 1])
|
||||
}
|
||||
}
|
||||
|
||||
func testSQLRequestWithArgumentsAndAdapter() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
let request = SQLRequest("SELECT ?, ?", arguments: [1, 2], adapter: SuffixRowAdapter(fromIndex: 1))
|
||||
let request = SQLRequest<Int>("SELECT ?, ?", arguments: [1, 2], adapter: SuffixRowAdapter(fromIndex: 1))
|
||||
let (statement, adapter) = try request.prepare(db)
|
||||
XCTAssertEqual(statement.sql, "SELECT ?, ?")
|
||||
XCTAssertNotNil(adapter)
|
||||
let int = try Int.fetchOne(db, request)!
|
||||
let int = try request.fetchOne(db)!
|
||||
XCTAssertEqual(int, 2)
|
||||
}
|
||||
}
|
||||
@@ -34,7 +36,7 @@ class SQLRequestTests: GRDBTestCase {
|
||||
func testNotCachedSQLRequest() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
let request = SQLRequest("SELECT 1")
|
||||
let request = SQLRequest<Row>("SELECT 1")
|
||||
let (statement1, _) = try request.prepare(db)
|
||||
let (statement2, _) = try request.prepare(db)
|
||||
XCTAssertTrue(statement1 !== statement2)
|
||||
@@ -44,25 +46,29 @@ class SQLRequestTests: GRDBTestCase {
|
||||
func testCachedSQLRequest() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
let request = SQLRequest("SELECT 1", cached: true)
|
||||
let request = SQLRequest<Row>("SELECT 1", cached: true)
|
||||
let (statement1, _) = try request.prepare(db)
|
||||
let (statement2, _) = try request.prepare(db)
|
||||
XCTAssertTrue(statement1 === statement2)
|
||||
}
|
||||
}
|
||||
|
||||
func testAsSQLRequest() throws {
|
||||
struct CustomRequest: Request {
|
||||
func testRequestInitializer() throws {
|
||||
struct CustomRequest: FetchRequest {
|
||||
typealias RowDecoder = Row
|
||||
func prepare(_ db: Database) throws -> (SelectStatement, RowAdapter?) {
|
||||
return try SQLRequest("SELECT ?, ?", arguments: [1, "foo"]).prepare(db)
|
||||
let statement = try db.makeSelectStatement("SELECT ? AS a, ? AS b")
|
||||
statement.arguments = [1, "foo"]
|
||||
return (statement, nil)
|
||||
}
|
||||
}
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
let request = CustomRequest()
|
||||
let sqlRequest = try request.asSQLRequest(db)
|
||||
XCTAssertEqual(sqlRequest.sql, "SELECT ?, ?")
|
||||
let sqlRequest = try SQLRequest(db, request: request)
|
||||
XCTAssertEqual(sqlRequest.sql, "SELECT ? AS a, ? AS b")
|
||||
XCTAssertEqual(sqlRequest.arguments, [1, "foo"])
|
||||
XCTAssertEqual(try sqlRequest.fetchOne(db)!, ["a": 1, "b": "foo"])
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -100,8 +100,7 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase {
|
||||
let statement = try db.makeSelectStatement(sql)
|
||||
try test(Fetched.fetchCursor(db, sql))
|
||||
try test(Fetched.fetchCursor(statement))
|
||||
try test(Fetched.fetchCursor(db, SQLRequest(sql)))
|
||||
try test(SQLRequest(sql).asRequest(of: Fetched.self).fetchCursor(db))
|
||||
try test(SQLRequest<Fetched>(sql).fetchCursor(db))
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT 0, 1 UNION ALL SELECT 0, 2"
|
||||
@@ -109,8 +108,7 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase {
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
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).asRequest(of: Fetched.self).fetchCursor(db))
|
||||
try test(SQLRequest<Fetched>(sql, adapter: adapter).fetchCursor(db))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -144,16 +142,14 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase {
|
||||
let sql = "SELECT throw()"
|
||||
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).asRequest(of: Fetched.self).fetchCursor(db), sql: sql)
|
||||
try test(SQLRequest<Fetched>(sql).fetchCursor(db), sql: sql)
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT 0, throw()"
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
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).asRequest(of: Fetched.self).fetchCursor(db), sql: sql)
|
||||
try test(SQLRequest<Fetched>(sql, adapter: adapter).fetchCursor(db), sql: sql)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -176,16 +172,14 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase {
|
||||
let sql = "SELECT * FROM nonExistingTable"
|
||||
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).asRequest(of: Fetched.self).fetchCursor(db), sql: sql)
|
||||
try test(SQLRequest<Fetched>(sql).fetchCursor(db), sql: sql)
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT * FROM nonExistingTable"
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
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).asRequest(of: Fetched.self).fetchCursor(db), sql: sql)
|
||||
try test(SQLRequest<Fetched>(sql, adapter: adapter).fetchCursor(db), sql: sql)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -202,8 +196,7 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase {
|
||||
let statement = try db.makeSelectStatement(sql)
|
||||
try test(Fetched.fetchAll(db, sql))
|
||||
try test(Fetched.fetchAll(statement))
|
||||
try test(Fetched.fetchAll(db, SQLRequest(sql)))
|
||||
try test(SQLRequest(sql).asRequest(of: Fetched.self).fetchAll(db))
|
||||
try test(SQLRequest<Fetched>(sql).fetchAll(db))
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT 0, 1 UNION ALL SELECT 0, 2"
|
||||
@@ -211,8 +204,7 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase {
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
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).asRequest(of: Fetched.self).fetchAll(db))
|
||||
try test(SQLRequest<Fetched>(sql, adapter: adapter).fetchAll(db))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -237,16 +229,14 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase {
|
||||
let sql = "SELECT throw()"
|
||||
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).asRequest(of: Fetched.self).fetchAll(db), sql: sql)
|
||||
try test(SQLRequest<Fetched>(sql).fetchAll(db), sql: sql)
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT 0, throw()"
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
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).asRequest(of: Fetched.self).fetchAll(db), sql: sql)
|
||||
try test(SQLRequest<Fetched>(sql, adapter: adapter).fetchAll(db), sql: sql)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -269,16 +259,14 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase {
|
||||
let sql = "SELECT * FROM nonExistingTable"
|
||||
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).asRequest(of: Fetched.self).fetchAll(db), sql: sql)
|
||||
try test(SQLRequest<Fetched>(sql).fetchAll(db), sql: sql)
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT * FROM nonExistingTable"
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
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).asRequest(of: Fetched.self).fetchAll(db), sql: sql)
|
||||
try test(SQLRequest<Fetched>(sql, adapter: adapter).fetchAll(db), sql: sql)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -295,8 +283,7 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase {
|
||||
let statement = try db.makeSelectStatement(sql)
|
||||
try test(Fetched.fetchOne(db, sql))
|
||||
try test(Fetched.fetchOne(statement))
|
||||
try test(Fetched.fetchOne(db, SQLRequest(sql)))
|
||||
try test(SQLRequest(sql).asRequest(of: Fetched.self).fetchOne(db))
|
||||
try test(SQLRequest<Fetched>(sql).fetchOne(db))
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT 0, 1 WHERE 0"
|
||||
@@ -304,8 +291,7 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase {
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
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).asRequest(of: Fetched.self).fetchOne(db))
|
||||
try test(SQLRequest<Fetched>(sql, adapter: adapter).fetchOne(db))
|
||||
}
|
||||
}
|
||||
do {
|
||||
@@ -317,8 +303,7 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase {
|
||||
let statement = try db.makeSelectStatement(sql)
|
||||
try test(Fetched.fetchOne(db, sql))
|
||||
try test(Fetched.fetchOne(statement))
|
||||
try test(Fetched.fetchOne(db, SQLRequest(sql)))
|
||||
try test(SQLRequest(sql).asRequest(of: Fetched.self).fetchOne(db))
|
||||
try test(SQLRequest<Fetched>(sql).fetchOne(db))
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT 0, NULL"
|
||||
@@ -326,8 +311,7 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase {
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
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).asRequest(of: Fetched.self).fetchOne(db))
|
||||
try test(SQLRequest<Fetched>(sql, adapter: adapter).fetchOne(db))
|
||||
}
|
||||
}
|
||||
do {
|
||||
@@ -339,8 +323,7 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase {
|
||||
let statement = try db.makeSelectStatement(sql)
|
||||
try test(Fetched.fetchOne(db, sql))
|
||||
try test(Fetched.fetchOne(statement))
|
||||
try test(Fetched.fetchOne(db, SQLRequest(sql)))
|
||||
try test(SQLRequest(sql).asRequest(of: Fetched.self).fetchOne(db))
|
||||
try test(SQLRequest<Fetched>(sql).fetchOne(db))
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT 0, 1"
|
||||
@@ -348,8 +331,7 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase {
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
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).asRequest(of: Fetched.self).fetchOne(db))
|
||||
try test(SQLRequest<Fetched>(sql, adapter: adapter).fetchOne(db))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -375,16 +357,14 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase {
|
||||
let sql = "SELECT throw()"
|
||||
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).asRequest(of: Fetched.self).fetchOne(db), sql: sql)
|
||||
try test(SQLRequest<Fetched>(sql).fetchOne(db), sql: sql)
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT 0, throw()"
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
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).asRequest(of: Fetched.self).fetchOne(db), sql: sql)
|
||||
try test(SQLRequest<Fetched>(sql, adapter: adapter).fetchOne(db), sql: sql)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -407,16 +387,14 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase {
|
||||
let sql = "SELECT * FROM nonExistingTable"
|
||||
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).asRequest(of: Fetched.self).fetchOne(db), sql: sql)
|
||||
try test(SQLRequest<Fetched>(sql).fetchOne(db), sql: sql)
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT * FROM nonExistingTable"
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
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).asRequest(of: Fetched.self).fetchOne(db), sql: sql)
|
||||
try test(SQLRequest<Fetched>(sql, adapter: adapter).fetchOne(db), sql: sql)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -438,8 +416,7 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase {
|
||||
let statement = try db.makeSelectStatement(sql)
|
||||
try test(Optional<Fetched>.fetchCursor(db, sql))
|
||||
try test(Optional<Fetched>.fetchCursor(statement))
|
||||
try test(Optional<Fetched>.fetchCursor(db, SQLRequest(sql)))
|
||||
try test(SQLRequest(sql).asRequest(of: Optional<Fetched>.self).fetchCursor(db))
|
||||
try test(SQLRequest<Fetched?>(sql).fetchCursor(db))
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT 0, 1 UNION ALL SELECT 0, NULL"
|
||||
@@ -447,8 +424,7 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase {
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
try test(Optional<Fetched>.fetchCursor(db, sql, adapter: adapter))
|
||||
try test(Optional<Fetched>.fetchCursor(statement, adapter: adapter))
|
||||
try test(Optional<Fetched>.fetchCursor(db, SQLRequest(sql, adapter: adapter)))
|
||||
try test(SQLRequest(sql, adapter: adapter).asRequest(of: Optional<Fetched>.self).fetchCursor(db))
|
||||
try test(SQLRequest<Fetched?>(sql, adapter: adapter).fetchCursor(db))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -471,16 +447,14 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase {
|
||||
let sql = "SELECT * FROM nonExistingTable"
|
||||
try test(Optional<Fetched>.fetchCursor(db, sql), sql: sql)
|
||||
try test(Optional<Fetched>.fetchCursor(db.makeSelectStatement(sql)), sql: sql)
|
||||
try test(Optional<Fetched>.fetchCursor(db, SQLRequest(sql)), sql: sql)
|
||||
try test(SQLRequest(sql).asRequest(of: Optional<Fetched>.self).fetchCursor(db), sql: sql)
|
||||
try test(SQLRequest<Fetched?>(sql).fetchCursor(db), sql: sql)
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT * FROM nonExistingTable"
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
try test(Optional<Fetched>.fetchCursor(db, sql, adapter: adapter), sql: sql)
|
||||
try test(Optional<Fetched>.fetchCursor(db.makeSelectStatement(sql), adapter: adapter), sql: sql)
|
||||
try test(Optional<Fetched>.fetchCursor(db, SQLRequest(sql, adapter: adapter)), sql: sql)
|
||||
try test(SQLRequest(sql, adapter: adapter).asRequest(of: Optional<Fetched>.self).fetchCursor(db), sql: sql)
|
||||
try test(SQLRequest<Fetched?>(sql, adapter: adapter).fetchCursor(db), sql: sql)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -499,8 +473,7 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase {
|
||||
let statement = try db.makeSelectStatement(sql)
|
||||
try test(Optional<Fetched>.fetchAll(db, sql))
|
||||
try test(Optional<Fetched>.fetchAll(statement))
|
||||
try test(Optional<Fetched>.fetchAll(db, SQLRequest(sql)))
|
||||
try test(SQLRequest(sql).asRequest(of: Optional<Fetched>.self).fetchAll(db))
|
||||
try test(SQLRequest<Fetched?>(sql).fetchAll(db))
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT 0, 1 UNION ALL SELECT 0, NULL"
|
||||
@@ -508,8 +481,7 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase {
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
try test(Optional<Fetched>.fetchAll(db, sql, adapter: adapter))
|
||||
try test(Optional<Fetched>.fetchAll(statement, adapter: adapter))
|
||||
try test(Optional<Fetched>.fetchAll(db, SQLRequest(sql, adapter: adapter)))
|
||||
try test(SQLRequest(sql, adapter: adapter).asRequest(of: Optional<Fetched>.self).fetchAll(db))
|
||||
try test(SQLRequest<Fetched?>(sql, adapter: adapter).fetchAll(db))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -534,16 +506,14 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase {
|
||||
let sql = "SELECT throw()"
|
||||
try test(Optional<Fetched>.fetchAll(db, sql), sql: sql)
|
||||
try test(Optional<Fetched>.fetchAll(db.makeSelectStatement(sql)), sql: sql)
|
||||
try test(Optional<Fetched>.fetchAll(db, SQLRequest(sql)), sql: sql)
|
||||
try test(SQLRequest(sql).asRequest(of: Optional<Fetched>.self).fetchAll(db), sql: sql)
|
||||
try test(SQLRequest<Fetched?>(sql).fetchAll(db), sql: sql)
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT 0, throw()"
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
try test(Optional<Fetched>.fetchAll(db, sql, adapter: adapter), sql: sql)
|
||||
try test(Optional<Fetched>.fetchAll(db.makeSelectStatement(sql), adapter: adapter), sql: sql)
|
||||
try test(Optional<Fetched>.fetchAll(db, SQLRequest(sql, adapter: adapter)), sql: sql)
|
||||
try test(SQLRequest(sql, adapter: adapter).asRequest(of: Optional<Fetched>.self).fetchAll(db), sql: sql)
|
||||
try test(SQLRequest<Fetched?>(sql, adapter: adapter).fetchAll(db), sql: sql)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -566,16 +536,14 @@ class StatementColumnConvertibleFetchTests: GRDBTestCase {
|
||||
let sql = "SELECT * FROM nonExistingTable"
|
||||
try test(Optional<Fetched>.fetchAll(db, sql), sql: sql)
|
||||
try test(Optional<Fetched>.fetchAll(db.makeSelectStatement(sql)), sql: sql)
|
||||
try test(Optional<Fetched>.fetchAll(db, SQLRequest(sql)), sql: sql)
|
||||
try test(SQLRequest(sql).asRequest(of: Optional<Fetched>.self).fetchAll(db), sql: sql)
|
||||
try test(SQLRequest<Fetched?>(sql).fetchAll(db), sql: sql)
|
||||
}
|
||||
do {
|
||||
let sql = "SELECT * FROM nonExistingTable"
|
||||
let adapter = SuffixRowAdapter(fromIndex: 1)
|
||||
try test(Optional<Fetched>.fetchAll(db, sql, adapter: adapter), sql: sql)
|
||||
try test(Optional<Fetched>.fetchAll(db.makeSelectStatement(sql), adapter: adapter), sql: sql)
|
||||
try test(Optional<Fetched>.fetchAll(db, SQLRequest(sql, adapter: adapter)), sql: sql)
|
||||
try test(SQLRequest(sql, adapter: adapter).asRequest(of: Optional<Fetched>.self).fetchAll(db), sql: sql)
|
||||
try test(SQLRequest<Fetched?>(sql, adapter: adapter).fetchAll(db), sql: sql)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ class TableMappingQueryInterfaceRequestTests: GRDBTestCase {
|
||||
try db.execute("INSERT INTO readers (name, age) VALUES (?, ?)", arguments: ["Barbara", 36])
|
||||
|
||||
let request = Reader.select(sql: "name, id - 1")
|
||||
let rows = try Row.fetchAll(db, request)
|
||||
let rows = try request.asRequest(of: Row.self).fetchAll(db)
|
||||
XCTAssertEqual(lastSQLQuery, "SELECT name, id - 1 FROM \"readers\"")
|
||||
XCTAssertEqual(rows.count, 2)
|
||||
XCTAssertEqual(rows[0][0] as String, "Arthur")
|
||||
@@ -108,7 +108,7 @@ class TableMappingQueryInterfaceRequestTests: GRDBTestCase {
|
||||
try db.execute("INSERT INTO readers (name, age) VALUES (?, ?)", arguments: ["Barbara", 36])
|
||||
|
||||
let request = Reader.select(sql: "name, id - ?", arguments: [1])
|
||||
let rows = try Row.fetchAll(db, request)
|
||||
let rows = try request.asRequest(of: Row.self).fetchAll(db)
|
||||
XCTAssertEqual(lastSQLQuery, "SELECT name, id - 1 FROM \"readers\"")
|
||||
XCTAssertEqual(rows.count, 2)
|
||||
XCTAssertEqual(rows[0][0] as String, "Arthur")
|
||||
@@ -125,7 +125,7 @@ class TableMappingQueryInterfaceRequestTests: GRDBTestCase {
|
||||
try db.execute("INSERT INTO readers (name, age) VALUES (?, ?)", arguments: ["Barbara", 36])
|
||||
|
||||
let request = Reader.select(sql: "name, id - :n", arguments: ["n": 1])
|
||||
let rows = try Row.fetchAll(db, request)
|
||||
let rows = try request.asRequest(of: Row.self).fetchAll(db)
|
||||
XCTAssertEqual(lastSQLQuery, "SELECT name, id - 1 FROM \"readers\"")
|
||||
XCTAssertEqual(rows.count, 2)
|
||||
XCTAssertEqual(rows[0][0] as String, "Arthur")
|
||||
@@ -142,7 +142,7 @@ class TableMappingQueryInterfaceRequestTests: GRDBTestCase {
|
||||
try db.execute("INSERT INTO readers (name, age) VALUES (?, ?)", arguments: ["Barbara", 36])
|
||||
|
||||
let request = Reader.select(Col.name, Col.id - 1)
|
||||
let rows = try Row.fetchAll(db, request)
|
||||
let rows = try request.asRequest(of: Row.self).fetchAll(db)
|
||||
XCTAssertEqual(lastSQLQuery, "SELECT \"name\", (\"id\" - 1) FROM \"readers\"")
|
||||
XCTAssertEqual(rows.count, 2)
|
||||
XCTAssertEqual(rows[0][0] as String, "Arthur")
|
||||
|
||||
Reference in new issue
Block a user