diff --git a/CHANGELOG.md b/CHANGELOG.md index a98d55709..2ba8eab75 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -95,6 +95,7 @@ GRDB adheres to [Semantic Versioning](https://semver.org/), with one exception: - [#748](https://github.com/groue/GRDB.swift/pull/748): Rename QueryInterfaceRequest to Request - [#749](https://github.com/groue/GRDB.swift/pull/749): Drop submodules used by performance tests - [#750](https://github.com/groue/GRDB.swift/pull/750): Batch updates do not need any operator +- [#752](https://github.com/groue/GRDB.swift/pull/752): Remove ValueObservation.combine ## 4.12.1 diff --git a/Documentation/GRDB5MigrationGuide.md b/Documentation/GRDB5MigrationGuide.md index 0d45f9b15..b82e6eed8 100644 --- a/Documentation/GRDB5MigrationGuide.md +++ b/Documentation/GRDB5MigrationGuide.md @@ -177,9 +177,41 @@ Those changes have been applied identically to [GRDBCombine] and [RxGRDB], so th 3. Some value observations used to automatically remove duplicate values. This is no longer automatic. If your application relies on distinct consecutive values, use the [removeDuplicates] operator. -4. ValueObservation used to have a `compactMap` method. This method has been removed without any replacement. +**ValueObservation features have been removed**. -5. ValueObservation used to let application define custom "reducers" using the ValueReducer protocol. These apis are no longer available. See the [#731](https://github.com/groue/GRDB.swift/pull/731) conversation for a solution towards a replacement. +1. ValueObservation used to have a `compactMap` method. This method has been removed without any replacement. + + If your application uses GRDBCombine or RxGRDB, then use the `compactMap` method from Combine or RxSwift instead. + +2. ValueObservation used to have a `combine` method. This method has been removed without any replacement. + + In your application, replace combined observations with a single observation: + + ```swift + // BEFORE: GRDB 4 + let playerCountObservation = ValueObservation.tracking(Player.fetchCount) + let bestPlayersObservation = ValueObservation.tracking(Player + .limit(10) + .order(Column("score").desc) + .fetchAll) + let observation = ValueObservation + .combine(playerCountObservation, bestPlayersObservation) + .map(HallOfFame.init) + + // NEW: GRDB 5 + let observation = ValueObservation.tracking { db -> HallOfFame in + let playerCount = try Player.fetchCount(db) + let bestPlayers = try Player + .limit(10) + .order(Column("score").desc) + .fetchAll(db) + return HallOfFame(playerCount: playerCount, bestPlayers: bestPlayers) + } + ``` + + As is previous versions of GRDB, do not use the `combineLatest` operators of Combine or RxSwift in order to combine several ValueObservation. You would lose all guarantees of [data consistency](https://en.wikipedia.org/wiki/Consistency_(database_systems)). + +3. ValueObservation used to let application define custom "reducers" using the ValueReducer protocol. These apis are no longer available. See the [#731](https://github.com/groue/GRDB.swift/pull/731) conversation for a solution towards a replacement. ## Other Changes diff --git a/GRDB.xcodeproj/project.pbxproj b/GRDB.xcodeproj/project.pbxproj index 7c0628440..baa5a157f 100755 --- a/GRDB.xcodeproj/project.pbxproj +++ b/GRDB.xcodeproj/project.pbxproj @@ -57,14 +57,9 @@ 5613ED3521A95A5C00DC7A68 /* Map.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5613ED3421A95A5C00DC7A68 /* Map.swift */; }; 5613ED3621A95A5C00DC7A68 /* Map.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5613ED3421A95A5C00DC7A68 /* Map.swift */; }; 5613ED3721A95A5C00DC7A68 /* Map.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5613ED3421A95A5C00DC7A68 /* Map.swift */; }; - 5613ED3F21A95A8B00DC7A68 /* Combine.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5613ED3E21A95A8B00DC7A68 /* Combine.swift */; }; - 5613ED4021A95A8B00DC7A68 /* Combine.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5613ED3E21A95A8B00DC7A68 /* Combine.swift */; }; - 5613ED4121A95A8B00DC7A68 /* Combine.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5613ED3E21A95A8B00DC7A68 /* Combine.swift */; }; 5613ED4421A95B2C00DC7A68 /* ValueReducer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5613ED4321A95B2C00DC7A68 /* ValueReducer.swift */; }; 5613ED4521A95B2C00DC7A68 /* ValueReducer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5613ED4321A95B2C00DC7A68 /* ValueReducer.swift */; }; 5613ED4621A95B2C00DC7A68 /* ValueReducer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5613ED4321A95B2C00DC7A68 /* ValueReducer.swift */; }; - 5613EDA621A96A9300DC7A68 /* ValueObservationCombineTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5613EDA521A96A9200DC7A68 /* ValueObservationCombineTests.swift */; }; - 5613EDA721A96A9300DC7A68 /* ValueObservationCombineTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5613EDA521A96A9200DC7A68 /* ValueObservationCombineTests.swift */; }; 5615B261222AE1B400061C1C /* AssociationHasOneThroughSQLDerivationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5615B25A222AE1B400061C1C /* AssociationHasOneThroughSQLDerivationTests.swift */; }; 5615B262222AE1B400061C1C /* AssociationHasOneThroughSQLDerivationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5615B25A222AE1B400061C1C /* AssociationHasOneThroughSQLDerivationTests.swift */; }; 5615B26A222AFE8F00061C1C /* AssociationHasOneThroughRowScopeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5615B269222AFE8F00061C1C /* AssociationHasOneThroughRowScopeTests.swift */; }; @@ -921,7 +916,6 @@ AAA4DCE6230F1E0600C74B15 /* SQLForeignKeyRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EAF920944C7B00F46237 /* SQLForeignKeyRequest.swift */; }; AAA4DCE7230F1E0600C74B15 /* NSData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5657AAB81D107001006283EF /* NSData.swift */; }; AAA4DCE8230F1E0600C74B15 /* FetchedRecordsController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 31A7787C1C6A4DD600F507F6 /* FetchedRecordsController.swift */; }; - AAA4DCE9230F1E0600C74B15 /* Combine.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5613ED3E21A95A8B00DC7A68 /* Combine.swift */; }; AAA4DCEA230F1E0600C74B15 /* DatabaseValue.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238751B9C75030082EB20 /* DatabaseValue.swift */; }; AAA4DCEB230F1E0600C74B15 /* SQLOrdering.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56CEB5431EAA359A00BFAF62 /* SQLOrdering.swift */; }; AAA4DCEC230F1E0600C74B15 /* Database+Schema.swift in Sources */ = {isa = PBXBuildFile; fileRef = 566B91221FA4CF810012D5B0 /* Database+Schema.swift */; }; @@ -1036,7 +1030,6 @@ AAA4DD6F230F262000C74B15 /* IndexInfoTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 567A80521D41350C00C7DCEC /* IndexInfoTests.swift */; }; AAA4DD70230F262000C74B15 /* ValueObservationFetchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563B06C92185D2E500B38F35 /* ValueObservationFetchTests.swift */; }; AAA4DD71230F262000C74B15 /* FilterCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 562393561DEE013C00A6B01F /* FilterCursorTests.swift */; }; - AAA4DD72230F262000C74B15 /* ValueObservationCombineTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5613EDA521A96A9200DC7A68 /* ValueObservationCombineTests.swift */; }; AAA4DD73230F262000C74B15 /* FetchableRecordDecodableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5674A7261F30A9090095F066 /* FetchableRecordDecodableTests.swift */; }; AAA4DD74230F262000C74B15 /* AssociationPrefetchingObservationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560432A2228F1667009D3FE2 /* AssociationPrefetchingObservationTests.swift */; }; AAA4DD75230F262000C74B15 /* MutablePersistableRecordChangesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 566A843F2041914000E50BFD /* MutablePersistableRecordChangesTests.swift */; }; @@ -1192,9 +1185,7 @@ 560D92441C672C4B00F4F92B /* PersistableRecord.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PersistableRecord.swift; sourceTree = ""; }; 560D92461C672C4B00F4F92B /* TableRecord.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TableRecord.swift; sourceTree = ""; }; 5613ED3421A95A5C00DC7A68 /* Map.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Map.swift; sourceTree = ""; }; - 5613ED3E21A95A8B00DC7A68 /* Combine.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Combine.swift; sourceTree = ""; }; 5613ED4321A95B2C00DC7A68 /* ValueReducer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ValueReducer.swift; sourceTree = ""; }; - 5613EDA521A96A9200DC7A68 /* ValueObservationCombineTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ValueObservationCombineTests.swift; sourceTree = ""; }; 5615B25A222AE1B400061C1C /* AssociationHasOneThroughSQLDerivationTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationHasOneThroughSQLDerivationTests.swift; sourceTree = ""; }; 5615B269222AFE8F00061C1C /* AssociationHasOneThroughRowScopeTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationHasOneThroughRowScopeTests.swift; sourceTree = ""; }; 5615B274222B107900061C1C /* AssociationHasOneThroughFetchableRecordTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationHasOneThroughFetchableRecordTests.swift; sourceTree = ""; }; @@ -1801,7 +1792,6 @@ 563B06BF2185CD1700B38F35 /* ValueObservation */ = { isa = PBXGroup; children = ( - 5613EDA521A96A9200DC7A68 /* ValueObservationCombineTests.swift */, 563B06F621861D8300B38F35 /* ValueObservationCountTests.swift */, 563B071721862F4C00B38F35 /* ValueObservationDatabaseValueConvertibleTests.swift */, 563B06C92185D2E500B38F35 /* ValueObservationFetchTests.swift */, @@ -2195,7 +2185,6 @@ 56AACAA022ACEC9700A40F2A /* ValueReducer */ = { isa = PBXGroup; children = ( - 5613ED3E21A95A8B00DC7A68 /* Combine.swift */, 56AACAA722ACED7100A40F2A /* Fetch.swift */, 5613ED3421A95A5C00DC7A68 /* Map.swift */, 564CE59621B7A8B500652B19 /* RemoveDuplicates.swift */, @@ -2757,7 +2746,6 @@ 565490D91D5AE252005622CB /* Migration.swift in Sources */, 56CEB5001EAA2F4D00BFAF62 /* FTS3.swift in Sources */, 5698AD271DABAEFA0056AF8C /* FTS5WrapperTokenizer.swift in Sources */, - 5613ED4121A95A8B00DC7A68 /* Combine.swift in Sources */, C96C0F2D2084A45A006B2981 /* SQLiteDateParser.swift in Sources */, 566A841C2041146100E50BFD /* DatabaseSnapshot.swift in Sources */, 565490D51D5AE252005622CB /* DatabaseValueConvertible+RawRepresentable.swift in Sources */, @@ -2974,7 +2962,6 @@ 5653EB0720944C7C00F46237 /* SQLForeignKeyRequest.swift in Sources */, 5657AABC1D107001006283EF /* NSData.swift in Sources */, 31A778841C6A4E0600F507F6 /* FetchedRecordsController.swift in Sources */, - 5613ED4021A95A8B00DC7A68 /* Combine.swift in Sources */, 56A238861B9C75030082EB20 /* DatabaseValue.swift in Sources */, 56CEB55D1EAA359A00BFAF62 /* SQLOrdering.swift in Sources */, 566B91261FA4CF810012D5B0 /* Database+Schema.swift in Sources */, @@ -3100,7 +3087,6 @@ 567A80571D41350C00C7DCEC /* IndexInfoTests.swift in Sources */, 563B06CB2185D2E500B38F35 /* ValueObservationFetchTests.swift in Sources */, 5623935B1DEE013C00A6B01F /* FilterCursorTests.swift in Sources */, - 5613EDA721A96A9300DC7A68 /* ValueObservationCombineTests.swift in Sources */, 5674A72D1F30A9090095F066 /* FetchableRecordDecodableTests.swift in Sources */, 560432A4228F1668009D3FE2 /* AssociationPrefetchingObservationTests.swift in Sources */, 566A84412041914000E50BFD /* MutablePersistableRecordChangesTests.swift in Sources */, @@ -3307,7 +3293,6 @@ 56D496B81D813465008276D7 /* DataMemoryTests.swift in Sources */, 563B06CA2185D2E500B38F35 /* ValueObservationFetchTests.swift in Sources */, 56D496541D812F5B008276D7 /* SQLExpressionLiteralTests.swift in Sources */, - 5613EDA621A96A9300DC7A68 /* ValueObservationCombineTests.swift in Sources */, 56D496961D81317B008276D7 /* PersistableRecordTests.swift in Sources */, 560432A3228F1668009D3FE2 /* AssociationPrefetchingObservationTests.swift in Sources */, 5698AC9E1DA4B0430056AF8C /* FTS4TableBuilderTests.swift in Sources */, @@ -3517,7 +3502,6 @@ AAA4DCE6230F1E0600C74B15 /* SQLForeignKeyRequest.swift in Sources */, AAA4DCE7230F1E0600C74B15 /* NSData.swift in Sources */, AAA4DCE8230F1E0600C74B15 /* FetchedRecordsController.swift in Sources */, - AAA4DCE9230F1E0600C74B15 /* Combine.swift in Sources */, AAA4DCEA230F1E0600C74B15 /* DatabaseValue.swift in Sources */, AAA4DCEB230F1E0600C74B15 /* SQLOrdering.swift in Sources */, AAA4DCEC230F1E0600C74B15 /* Database+Schema.swift in Sources */, @@ -3643,7 +3627,6 @@ AAA4DD6F230F262000C74B15 /* IndexInfoTests.swift in Sources */, AAA4DD70230F262000C74B15 /* ValueObservationFetchTests.swift in Sources */, AAA4DD71230F262000C74B15 /* FilterCursorTests.swift in Sources */, - AAA4DD72230F262000C74B15 /* ValueObservationCombineTests.swift in Sources */, AAA4DD73230F262000C74B15 /* FetchableRecordDecodableTests.swift in Sources */, AAA4DD74230F262000C74B15 /* AssociationPrefetchingObservationTests.swift in Sources */, AAA4DD75230F262000C74B15 /* MutablePersistableRecordChangesTests.swift in Sources */, @@ -3752,7 +3735,6 @@ 563EF44A2161F179007DAACD /* Inflections.swift in Sources */, 566B91091FA4C3970012D5B0 /* Database+Statements.swift in Sources */, 566B91231FA4CF810012D5B0 /* Database+Schema.swift in Sources */, - 5613ED3F21A95A8B00DC7A68 /* Combine.swift in Sources */, 563B06AB217EF0CC00B38F35 /* ValueObservation.swift in Sources */, 56CEB5111EAA324B00BFAF62 /* FTS3+QueryInterface.swift in Sources */, 5659F4901EA8D964004A4992 /* ReadWriteBox.swift in Sources */, diff --git a/GRDB.xcworkspace/contents.xcworkspacedata b/GRDB.xcworkspace/contents.xcworkspacedata index 8c3a19c03..4919b79c0 100644 --- a/GRDB.xcworkspace/contents.xcworkspacedata +++ b/GRDB.xcworkspace/contents.xcworkspacedata @@ -47,9 +47,6 @@ - - diff --git a/GRDB/Fixit/GRDB-5.0.swift b/GRDB/Fixit/GRDB-5.0.swift index a536551a3..9ba19f85e 100644 --- a/GRDB/Fixit/GRDB-5.0.swift +++ b/GRDB/Fixit/GRDB-5.0.swift @@ -12,7 +12,7 @@ extension AnyFetchRequest { { preconditionFailure() } } -@available(*, unavailable, message: "Custom reducers are no longer supported") +@available(*, unavailable, message: "Custom reducers are no longer supported. See the \"Migrating From GRDB 4 to GRDB 5\" guide.") public struct AnyValueReducer: _ValueReducer { public var isObservedRegionDeterministic: Bool { preconditionFailure() } @@ -213,15 +213,63 @@ extension ValueObservation { set { preconditionFailure() } } - @available(*, unavailable, message: "Custom reducers are no longer supported") + @available(*, unavailable, message: "Custom reducers are no longer supported. See the \"Migrating From GRDB 4 to GRDB 5\" guide.") public static func tracking(_ regions: DatabaseRegionConvertible..., reducer: @escaping (Database) throws -> Reducer) -> ValueObservation { preconditionFailure() } - @available(*, unavailable, message: "Custom reducers are no longer supported") + @available(*, unavailable, message: "Custom reducers are no longer supported. See the \"Migrating From GRDB 4 to GRDB 5\" guide.") public static func tracking(_ regions: [DatabaseRegionConvertible], reducer: @escaping (Database) throws -> Reducer) -> ValueObservation { preconditionFailure() } - @available(*, unavailable, message: "compactMap is no longer available") + @available(*, unavailable, message: "combine is no longer available. See the \"Migrating From GRDB 4 to GRDB 5\" guide.") + public func combine< + R1: _ValueReducer, + Combined>( + _ other: ValueObservation, + _ transform: @escaping (Reducer.Value, R1.Value) -> Combined) + -> ValueObservation> + { preconditionFailure() } + + @available(*, unavailable, message: "combine is no longer available. See the \"Migrating From GRDB 4 to GRDB 5\" guide.") + public func combine< + R1: _ValueReducer, + R2: _ValueReducer, + Combined>( + _ observation1: ValueObservation, + _ observation2: ValueObservation, + _ transform: @escaping (Reducer.Value, R1.Value, R2.Value) -> Combined) + -> ValueObservation> + { preconditionFailure() } + + @available(*, unavailable, message: "combine is no longer available. See the \"Migrating From GRDB 4 to GRDB 5\" guide.") + public func combine< + R1: _ValueReducer, + R2: _ValueReducer, + R3: _ValueReducer, + Combined>( + _ observation1: ValueObservation, + _ observation2: ValueObservation, + _ observation3: ValueObservation, + _ transform: @escaping (Reducer.Value, R1.Value, R2.Value, R3.Value) -> Combined) + -> ValueObservation> + { preconditionFailure() } + + @available(*, unavailable, message: "combine is no longer available. See the \"Migrating From GRDB 4 to GRDB 5\" guide.") + public func combine< + R1: _ValueReducer, + R2: _ValueReducer, + R3: _ValueReducer, + R4: _ValueReducer, + Combined>( + _ observation1: ValueObservation, + _ observation2: ValueObservation, + _ observation3: ValueObservation, + _ observation4: ValueObservation, + _ transform: @escaping (Reducer.Value, R1.Value, R2.Value, R3.Value, R4.Value) -> Combined) + -> ValueObservation> + { preconditionFailure() } + + @available(*, unavailable, message: "compactMap is no longer available. See the \"Migrating From GRDB 4 to GRDB 5\" guide.") public func compactMap(_ transform: @escaping (Reducer.Value) -> T?) -> ValueObservation> { preconditionFailure() } @@ -233,6 +281,111 @@ extension ValueObservation { } extension ValueObservation where Reducer == ValueReducers.Auto { + @available(*, unavailable, message: "combine is no longer available. See the \"Migrating From GRDB 4 to GRDB 5\" guide.") + public static func combine< + R1: _ValueReducer, + R2: _ValueReducer>( + _ o1: ValueObservation, + _ o2: ValueObservation) + -> ValueObservation> + { preconditionFailure() } + + @available(*, unavailable, message: "combine is no longer available. See the \"Migrating From GRDB 4 to GRDB 5\" guide.") + public static func combine< + R1: _ValueReducer, + R2: _ValueReducer, + R3: _ValueReducer>( + _ o1: ValueObservation, + _ o2: ValueObservation, + _ o3: ValueObservation) + -> ValueObservation> + { preconditionFailure() } + + @available(*, unavailable, message: "combine is no longer available. See the \"Migrating From GRDB 4 to GRDB 5\" guide.") + public static func combine< + R1: _ValueReducer, + R2: _ValueReducer, + R3: _ValueReducer, + R4: _ValueReducer>( + _ o1: ValueObservation, + _ o2: ValueObservation, + _ o3: ValueObservation, + _ o4: ValueObservation) + -> ValueObservation> + { preconditionFailure() } + + @available(*, unavailable, message: "combine is no longer available. See the \"Migrating From GRDB 4 to GRDB 5\" guide.") + public static func combine< + R1: _ValueReducer, + R2: _ValueReducer, + R3: _ValueReducer, + R4: _ValueReducer, + R5: _ValueReducer>( + _ o1: ValueObservation, + _ o2: ValueObservation, + _ o3: ValueObservation, + _ o4: ValueObservation, + _ o5: ValueObservation) + -> ValueObservation> + { preconditionFailure() } + + @available(*, unavailable, message: "combine is no longer available. See the \"Migrating From GRDB 4 to GRDB 5\" guide.") + public static func combine< + R1: _ValueReducer, + R2: _ValueReducer, + R3: _ValueReducer, + R4: _ValueReducer, + R5: _ValueReducer, + R6: _ValueReducer>( + _ o1: ValueObservation, + _ o2: ValueObservation, + _ o3: ValueObservation, + _ o4: ValueObservation, + _ o5: ValueObservation, + _ o6: ValueObservation) + -> ValueObservation> + { preconditionFailure() } + + @available(*, unavailable, message: "combine is no longer available. See the \"Migrating From GRDB 4 to GRDB 5\" guide.") + public static func combine< + R1: _ValueReducer, + R2: _ValueReducer, + R3: _ValueReducer, + R4: _ValueReducer, + R5: _ValueReducer, + R6: _ValueReducer, + R7: _ValueReducer>( + _ o1: ValueObservation, + _ o2: ValueObservation, + _ o3: ValueObservation, + _ o4: ValueObservation, + _ o5: ValueObservation, + _ o6: ValueObservation, + _ o7: ValueObservation) + -> ValueObservation> + { preconditionFailure() } + + @available(*, unavailable, message: "combine is no longer available. See the \"Migrating From GRDB 4 to GRDB 5\" guide.") + public static func combine< + R1: _ValueReducer, + R2: _ValueReducer, + R3: _ValueReducer, + R4: _ValueReducer, + R5: _ValueReducer, + R6: _ValueReducer, + R7: _ValueReducer, + R8: _ValueReducer>( + _ o1: ValueObservation, + _ o2: ValueObservation, + _ o3: ValueObservation, + _ o4: ValueObservation, + _ o5: ValueObservation, + _ o6: ValueObservation, + _ o7: ValueObservation, + _ o8: ValueObservation) + -> ValueObservation> + { preconditionFailure() } + @available(*, unavailable, message: "Use ValueObservation.tracking(_:) instead") public static func trackingCount(_ request: Request) -> ValueObservation> @@ -321,7 +474,7 @@ extension ValueReducers { } } -@available(*, unavailable, message: "Custom reducers are no longer supported") +@available(*, unavailable, message: "Custom reducers are no longer supported. See the \"Migrating From GRDB 4 to GRDB 5\" guide.") typealias ValueReducer = _ValueReducer @available(*, unavailable, message: "ValueObservation now schedules its values asynchronously on the main queue by default. See ValueObservation.start() for possible configuration") diff --git a/GRDB/ValueObservation/ValueReducer/Combine.swift b/GRDB/ValueObservation/ValueReducer/Combine.swift deleted file mode 100644 index 0b94b8cae..000000000 --- a/GRDB/ValueObservation/ValueReducer/Combine.swift +++ /dev/null @@ -1,813 +0,0 @@ -// MARK: - Combine 2 Reducers - -extension ValueReducers { - public struct Combine2< - R1: _ValueReducer, - R2: _ValueReducer>: _ValueReducer - { - public typealias Fetched = (R1.Fetched, R2.Fetched) - public typealias Value = (R1.Value, R2.Value) - var r1: R1 - var r2: R2 - private var p1: R1.Value? - private var p2: R2.Value? - - public var isObservedRegionDeterministic: Bool { - r1.isObservedRegionDeterministic - && r2.isObservedRegionDeterministic - } - - init(_ r1: R1, _ r2: R2) { - self.r1 = r1 - self.r2 = r2 - } - - public func fetch(_ db: Database) throws -> Fetched { - try ( - r1.fetch(db), - r2.fetch(db)) - } - - public mutating func value(_ fetched: Fetched) -> Value? { - let v1 = r1.value(fetched.0) - let v2 = r2.value(fetched.1) - defer { - if let v1 = v1 { p1 = v1 } - if let v2 = v2 { p2 = v2 } - } - if v1 != nil || v2 != nil, - let c1 = v1 ?? p1, - let c2 = v2 ?? p2 - { - return (c1, c2) - } else { - return nil - } - } - } -} - -extension ValueObservation where Reducer == ValueReducers.Auto { - public static func combine< - R1: _ValueReducer, - R2: _ValueReducer>( - _ o1: ValueObservation, - _ o2: ValueObservation) - -> ValueObservation> - { - return ValueObservation( - makeReducer: { ValueReducers.Combine2( - o1.makeReducer(), - o2.makeReducer()) }, - requiresWriteAccess: o1.requiresWriteAccess - || o2.requiresWriteAccess) - } -} - -extension ValueObservation where Reducer: _ValueReducer { - public func combine< - R1: _ValueReducer, - Combined>( - _ other: ValueObservation, - _ transform: @escaping (Reducer.Value, R1.Value) -> Combined) - -> ValueObservation, Combined>> - { - return ValueObservation.combine(self, other).map(transform) - } -} - -// MARK: - Combine 3 Reducers - -extension ValueReducers { - public struct Combine3< - R1: _ValueReducer, - R2: _ValueReducer, - R3: _ValueReducer>: _ValueReducer - { - public typealias Fetched = (R1.Fetched, R2.Fetched, R3.Fetched) - public typealias Value = (R1.Value, R2.Value, R3.Value) - var r1: R1 - var r2: R2 - var r3: R3 - private var p1: R1.Value? - private var p2: R2.Value? - private var p3: R3.Value? - - public var isObservedRegionDeterministic: Bool { - r1.isObservedRegionDeterministic - && r2.isObservedRegionDeterministic - && r3.isObservedRegionDeterministic - } - - init(_ r1: R1, _ r2: R2, _ r3: R3) { - self.r1 = r1 - self.r2 = r2 - self.r3 = r3 - } - - public func fetch(_ db: Database) throws -> Fetched { - try ( - r1.fetch(db), - r2.fetch(db), - r3.fetch(db)) - } - - public mutating func value(_ fetched: Fetched) -> Value? { - let v1 = r1.value(fetched.0) - let v2 = r2.value(fetched.1) - let v3 = r3.value(fetched.2) - defer { - if let v1 = v1 { p1 = v1 } - if let v2 = v2 { p2 = v2 } - if let v3 = v3 { p3 = v3 } - } - if v1 != nil || v2 != nil || v3 != nil, - let c1 = v1 ?? p1, - let c2 = v2 ?? p2, - let c3 = v3 ?? p3 - { - return (c1, c2, c3) - } else { - return nil - } - } - } -} - -extension ValueObservation where Reducer == ValueReducers.Auto { - public static func combine< - R1: _ValueReducer, - R2: _ValueReducer, - R3: _ValueReducer>( - _ o1: ValueObservation, - _ o2: ValueObservation, - _ o3: ValueObservation) - -> ValueObservation> - { - return ValueObservation( - makeReducer: { ValueReducers.Combine3( - o1.makeReducer(), - o2.makeReducer(), - o3.makeReducer()) }, - requiresWriteAccess: o1.requiresWriteAccess - || o2.requiresWriteAccess - || o3.requiresWriteAccess) - } -} - -extension ValueObservation where Reducer: _ValueReducer { - public func combine< - R1: _ValueReducer, - R2: _ValueReducer, - Combined>( - _ observation1: ValueObservation, - _ observation2: ValueObservation, - _ transform: @escaping (Reducer.Value, R1.Value, R2.Value) -> Combined) - -> ValueObservation, Combined>> - { - return ValueObservation - .combine( - self, - observation1, - observation2) - .map(transform) - } -} - -// MARK: - Combine 4 Reducers - -extension ValueReducers { - public struct Combine4< - R1: _ValueReducer, - R2: _ValueReducer, - R3: _ValueReducer, - R4: _ValueReducer>: _ValueReducer - { - public typealias Fetched = (R1.Fetched, R2.Fetched, R3.Fetched, R4.Fetched) - public typealias Value = (R1.Value, R2.Value, R3.Value, R4.Value) - var r1: R1 - var r2: R2 - var r3: R3 - var r4: R4 - private var p1: R1.Value? - private var p2: R2.Value? - private var p3: R3.Value? - private var p4: R4.Value? - - public var isObservedRegionDeterministic: Bool { - r1.isObservedRegionDeterministic - && r2.isObservedRegionDeterministic - && r3.isObservedRegionDeterministic - && r4.isObservedRegionDeterministic - } - - init(_ r1: R1, _ r2: R2, _ r3: R3, _ r4: R4) { - self.r1 = r1 - self.r2 = r2 - self.r3 = r3 - self.r4 = r4 - } - - public func fetch(_ db: Database) throws -> Fetched { - try ( - r1.fetch(db), - r2.fetch(db), - r3.fetch(db), - r4.fetch(db)) - } - - public mutating func value(_ fetched: Fetched) -> Value? { - let v1 = r1.value(fetched.0) - let v2 = r2.value(fetched.1) - let v3 = r3.value(fetched.2) - let v4 = r4.value(fetched.3) - defer { - if let v1 = v1 { p1 = v1 } - if let v2 = v2 { p2 = v2 } - if let v3 = v3 { p3 = v3 } - if let v4 = v4 { p4 = v4 } - } - if v1 != nil || v2 != nil || v3 != nil || v4 != nil, - let c1 = v1 ?? p1, - let c2 = v2 ?? p2, - let c3 = v3 ?? p3, - let c4 = v4 ?? p4 - { - return (c1, c2, c3, c4) - } else { - return nil - } - } - } -} - -extension ValueObservation where Reducer == ValueReducers.Auto { - public static func combine< - R1: _ValueReducer, - R2: _ValueReducer, - R3: _ValueReducer, - R4: _ValueReducer>( - _ o1: ValueObservation, - _ o2: ValueObservation, - _ o3: ValueObservation, - _ o4: ValueObservation) - -> ValueObservation> - { - return ValueObservation( - makeReducer: { ValueReducers.Combine4( - o1.makeReducer(), - o2.makeReducer(), - o3.makeReducer(), - o4.makeReducer()) }, - requiresWriteAccess: o1.requiresWriteAccess - || o2.requiresWriteAccess - || o3.requiresWriteAccess - || o4.requiresWriteAccess) - } -} - -extension ValueObservation where Reducer: _ValueReducer { - public func combine< - R1: _ValueReducer, - R2: _ValueReducer, - R3: _ValueReducer, - Combined>( - _ observation1: ValueObservation, - _ observation2: ValueObservation, - _ observation3: ValueObservation, - _ transform: @escaping (Reducer.Value, R1.Value, R2.Value, R3.Value) -> Combined) - -> ValueObservation, Combined>> - { - return ValueObservation - .combine( - self, - observation1, - observation2, - observation3) - .map(transform) - } -} - -// MARK: - Combine 5 Reducers - -extension ValueReducers { - public struct Combine5< - R1: _ValueReducer, - R2: _ValueReducer, - R3: _ValueReducer, - R4: _ValueReducer, - R5: _ValueReducer>: _ValueReducer - { - public typealias Fetched = (R1.Fetched, R2.Fetched, R3.Fetched, R4.Fetched, R5.Fetched) - public typealias Value = (R1.Value, R2.Value, R3.Value, R4.Value, R5.Value) - var r1: R1 - var r2: R2 - var r3: R3 - var r4: R4 - var r5: R5 - private var p1: R1.Value? - private var p2: R2.Value? - private var p3: R3.Value? - private var p4: R4.Value? - private var p5: R5.Value? - - public var isObservedRegionDeterministic: Bool { - r1.isObservedRegionDeterministic - && r2.isObservedRegionDeterministic - && r3.isObservedRegionDeterministic - && r4.isObservedRegionDeterministic - && r5.isObservedRegionDeterministic - } - - init(_ r1: R1, _ r2: R2, _ r3: R3, _ r4: R4, _ r5: R5) { - self.r1 = r1 - self.r2 = r2 - self.r3 = r3 - self.r4 = r4 - self.r5 = r5 - } - - public func fetch(_ db: Database) throws -> Fetched { - try ( - r1.fetch(db), - r2.fetch(db), - r3.fetch(db), - r4.fetch(db), - r5.fetch(db)) - } - - public mutating func value(_ fetched: Fetched) -> Value? { - let v1 = r1.value(fetched.0) - let v2 = r2.value(fetched.1) - let v3 = r3.value(fetched.2) - let v4 = r4.value(fetched.3) - let v5 = r5.value(fetched.4) - defer { - if let v1 = v1 { p1 = v1 } - if let v2 = v2 { p2 = v2 } - if let v3 = v3 { p3 = v3 } - if let v4 = v4 { p4 = v4 } - if let v5 = v5 { p5 = v5 } - } - if v1 != nil || v2 != nil || v3 != nil || v4 != nil || v5 != nil, - let c1 = v1 ?? p1, - let c2 = v2 ?? p2, - let c3 = v3 ?? p3, - let c4 = v4 ?? p4, - let c5 = v5 ?? p5 - { - return (c1, c2, c3, c4, c5) - } else { - return nil - } - } - } -} - -extension ValueObservation where Reducer == ValueReducers.Auto { - public static func combine< - R1: _ValueReducer, - R2: _ValueReducer, - R3: _ValueReducer, - R4: _ValueReducer, - R5: _ValueReducer>( - _ o1: ValueObservation, - _ o2: ValueObservation, - _ o3: ValueObservation, - _ o4: ValueObservation, - _ o5: ValueObservation) - -> ValueObservation> - { - return ValueObservation( - makeReducer: { ValueReducers.Combine5( - o1.makeReducer(), - o2.makeReducer(), - o3.makeReducer(), - o4.makeReducer(), - o5.makeReducer()) }, - requiresWriteAccess: o1.requiresWriteAccess - || o2.requiresWriteAccess - || o3.requiresWriteAccess - || o4.requiresWriteAccess - || o5.requiresWriteAccess) - } -} - -extension ValueObservation where Reducer: _ValueReducer { - public func combine< - R1: _ValueReducer, - R2: _ValueReducer, - R3: _ValueReducer, - R4: _ValueReducer, - Combined>( - _ observation1: ValueObservation, - _ observation2: ValueObservation, - _ observation3: ValueObservation, - _ observation4: ValueObservation, - _ transform: @escaping (Reducer.Value, R1.Value, R2.Value, R3.Value, R4.Value) -> Combined) - -> ValueObservation, Combined>> - { - return ValueObservation - .combine( - self, - observation1, - observation2, - observation3, - observation4) - .map(transform) - } -} - -// MARK: - Combine 6 Reducers - -extension ValueReducers { - public struct Combine6< - R1: _ValueReducer, - R2: _ValueReducer, - R3: _ValueReducer, - R4: _ValueReducer, - R5: _ValueReducer, - R6: _ValueReducer>: _ValueReducer - { - public typealias Fetched = (R1.Fetched, R2.Fetched, R3.Fetched, R4.Fetched, R5.Fetched, R6.Fetched) - public typealias Value = (R1.Value, R2.Value, R3.Value, R4.Value, R5.Value, R6.Value) - var r1: R1 - var r2: R2 - var r3: R3 - var r4: R4 - var r5: R5 - var r6: R6 - private var p1: R1.Value? - private var p2: R2.Value? - private var p3: R3.Value? - private var p4: R4.Value? - private var p5: R5.Value? - private var p6: R6.Value? - - public var isObservedRegionDeterministic: Bool { - r1.isObservedRegionDeterministic - && r2.isObservedRegionDeterministic - && r3.isObservedRegionDeterministic - && r4.isObservedRegionDeterministic - && r5.isObservedRegionDeterministic - && r6.isObservedRegionDeterministic - } - - init(_ r1: R1, _ r2: R2, _ r3: R3, _ r4: R4, _ r5: R5, _ r6: R6) { - self.r1 = r1 - self.r2 = r2 - self.r3 = r3 - self.r4 = r4 - self.r5 = r5 - self.r6 = r6 - } - - public func fetch(_ db: Database) throws -> Fetched { - try ( - r1.fetch(db), - r2.fetch(db), - r3.fetch(db), - r4.fetch(db), - r5.fetch(db), - r6.fetch(db)) - } - - public mutating func value(_ fetched: Fetched) -> Value? { - let v1 = r1.value(fetched.0) - let v2 = r2.value(fetched.1) - let v3 = r3.value(fetched.2) - let v4 = r4.value(fetched.3) - let v5 = r5.value(fetched.4) - let v6 = r6.value(fetched.5) - defer { - if let v1 = v1 { p1 = v1 } - if let v2 = v2 { p2 = v2 } - if let v3 = v3 { p3 = v3 } - if let v4 = v4 { p4 = v4 } - if let v5 = v5 { p5 = v5 } - if let v6 = v6 { p6 = v6 } - } - if v1 != nil || v2 != nil || v3 != nil || v4 != nil || v5 != nil || v6 != nil, - let c1 = v1 ?? p1, - let c2 = v2 ?? p2, - let c3 = v3 ?? p3, - let c4 = v4 ?? p4, - let c5 = v5 ?? p5, - let c6 = v6 ?? p6 - { - return (c1, c2, c3, c4, c5, c6) - } else { - return nil - } - } - } -} - -extension ValueObservation where Reducer == ValueReducers.Auto { - public static func combine< - R1: _ValueReducer, - R2: _ValueReducer, - R3: _ValueReducer, - R4: _ValueReducer, - R5: _ValueReducer, - R6: _ValueReducer>( - _ o1: ValueObservation, - _ o2: ValueObservation, - _ o3: ValueObservation, - _ o4: ValueObservation, - _ o5: ValueObservation, - _ o6: ValueObservation) - -> ValueObservation> - { - return ValueObservation( - makeReducer: { ValueReducers.Combine6( - o1.makeReducer(), - o2.makeReducer(), - o3.makeReducer(), - o4.makeReducer(), - o5.makeReducer(), - o6.makeReducer()) }, - requiresWriteAccess: o1.requiresWriteAccess - || o2.requiresWriteAccess - || o3.requiresWriteAccess - || o4.requiresWriteAccess - || o5.requiresWriteAccess - || o6.requiresWriteAccess) - } -} - -// MARK: - Combine 7 Reducers - -extension ValueReducers { - public struct Combine7< - R1: _ValueReducer, - R2: _ValueReducer, - R3: _ValueReducer, - R4: _ValueReducer, - R5: _ValueReducer, - R6: _ValueReducer, - R7: _ValueReducer>: _ValueReducer - { - public typealias Fetched = (R1.Fetched, R2.Fetched, R3.Fetched, R4.Fetched, R5.Fetched, R6.Fetched, R7.Fetched) - public typealias Value = (R1.Value, R2.Value, R3.Value, R4.Value, R5.Value, R6.Value, R7.Value) - var r1: R1 - var r2: R2 - var r3: R3 - var r4: R4 - var r5: R5 - var r6: R6 - var r7: R7 - private var p1: R1.Value? - private var p2: R2.Value? - private var p3: R3.Value? - private var p4: R4.Value? - private var p5: R5.Value? - private var p6: R6.Value? - private var p7: R7.Value? - - public var isObservedRegionDeterministic: Bool { - r1.isObservedRegionDeterministic - && r2.isObservedRegionDeterministic - && r3.isObservedRegionDeterministic - && r4.isObservedRegionDeterministic - && r5.isObservedRegionDeterministic - && r6.isObservedRegionDeterministic - && r7.isObservedRegionDeterministic - } - - init(_ r1: R1, _ r2: R2, _ r3: R3, _ r4: R4, _ r5: R5, _ r6: R6, _ r7: R7) { - self.r1 = r1 - self.r2 = r2 - self.r3 = r3 - self.r4 = r4 - self.r5 = r5 - self.r6 = r6 - self.r7 = r7 - } - - public func fetch(_ db: Database) throws -> Fetched { - try ( - r1.fetch(db), - r2.fetch(db), - r3.fetch(db), - r4.fetch(db), - r5.fetch(db), - r6.fetch(db), - r7.fetch(db)) - } - - public mutating func value(_ fetched: Fetched) -> Value? { - let v1 = r1.value(fetched.0) - let v2 = r2.value(fetched.1) - let v3 = r3.value(fetched.2) - let v4 = r4.value(fetched.3) - let v5 = r5.value(fetched.4) - let v6 = r6.value(fetched.5) - let v7 = r7.value(fetched.6) - defer { - if let v1 = v1 { p1 = v1 } - if let v2 = v2 { p2 = v2 } - if let v3 = v3 { p3 = v3 } - if let v4 = v4 { p4 = v4 } - if let v5 = v5 { p5 = v5 } - if let v6 = v6 { p6 = v6 } - if let v7 = v7 { p7 = v7 } - } - if v1 != nil || v2 != nil || v3 != nil || v4 != nil || v5 != nil || v6 != nil || v7 != nil, - let c1 = v1 ?? p1, - let c2 = v2 ?? p2, - let c3 = v3 ?? p3, - let c4 = v4 ?? p4, - let c5 = v5 ?? p5, - let c6 = v6 ?? p6, - let c7 = v7 ?? p7 - { - return (c1, c2, c3, c4, c5, c6, c7) - } else { - return nil - } - } - } -} - -extension ValueObservation where Reducer == ValueReducers.Auto { - public static func combine< - R1: _ValueReducer, - R2: _ValueReducer, - R3: _ValueReducer, - R4: _ValueReducer, - R5: _ValueReducer, - R6: _ValueReducer, - R7: _ValueReducer>( - _ o1: ValueObservation, - _ o2: ValueObservation, - _ o3: ValueObservation, - _ o4: ValueObservation, - _ o5: ValueObservation, - _ o6: ValueObservation, - _ o7: ValueObservation) - -> ValueObservation> - { - return ValueObservation( - makeReducer: { ValueReducers.Combine7( - o1.makeReducer(), - o2.makeReducer(), - o3.makeReducer(), - o4.makeReducer(), - o5.makeReducer(), - o6.makeReducer(), - o7.makeReducer()) }, - requiresWriteAccess: o1.requiresWriteAccess - || o2.requiresWriteAccess - || o3.requiresWriteAccess - || o4.requiresWriteAccess - || o5.requiresWriteAccess - || o6.requiresWriteAccess - || o7.requiresWriteAccess) - } -} - -// MARK: - Combine 8 Reducers - -extension ValueReducers { - public struct Combine8< - R1: _ValueReducer, - R2: _ValueReducer, - R3: _ValueReducer, - R4: _ValueReducer, - R5: _ValueReducer, - R6: _ValueReducer, - R7: _ValueReducer, - R8: _ValueReducer>: _ValueReducer - { - // swiftlint:disable:next line_length - public typealias Fetched = (R1.Fetched, R2.Fetched, R3.Fetched, R4.Fetched, R5.Fetched, R6.Fetched, R7.Fetched, R8.Fetched) - public typealias Value = (R1.Value, R2.Value, R3.Value, R4.Value, R5.Value, R6.Value, R7.Value, R8.Value) - var r1: R1 - var r2: R2 - var r3: R3 - var r4: R4 - var r5: R5 - var r6: R6 - var r7: R7 - var r8: R8 - private var p1: R1.Value? - private var p2: R2.Value? - private var p3: R3.Value? - private var p4: R4.Value? - private var p5: R5.Value? - private var p6: R6.Value? - private var p7: R7.Value? - private var p8: R8.Value? - - public var isObservedRegionDeterministic: Bool { - r1.isObservedRegionDeterministic - && r2.isObservedRegionDeterministic - && r3.isObservedRegionDeterministic - && r4.isObservedRegionDeterministic - && r5.isObservedRegionDeterministic - && r6.isObservedRegionDeterministic - && r7.isObservedRegionDeterministic - && r8.isObservedRegionDeterministic - } - - init(_ r1: R1, _ r2: R2, _ r3: R3, _ r4: R4, _ r5: R5, _ r6: R6, _ r7: R7, _ r8: R8) { - self.r1 = r1 - self.r2 = r2 - self.r3 = r3 - self.r4 = r4 - self.r5 = r5 - self.r6 = r6 - self.r7 = r7 - self.r8 = r8 - } - - public func fetch(_ db: Database) throws -> Fetched { - try ( - r1.fetch(db), - r2.fetch(db), - r3.fetch(db), - r4.fetch(db), - r5.fetch(db), - r6.fetch(db), - r7.fetch(db), - r8.fetch(db)) - } - - public mutating func value(_ fetched: Fetched) -> Value? { - let v1 = r1.value(fetched.0) - let v2 = r2.value(fetched.1) - let v3 = r3.value(fetched.2) - let v4 = r4.value(fetched.3) - let v5 = r5.value(fetched.4) - let v6 = r6.value(fetched.5) - let v7 = r7.value(fetched.6) - let v8 = r8.value(fetched.7) - defer { - if let v1 = v1 { p1 = v1 } - if let v2 = v2 { p2 = v2 } - if let v3 = v3 { p3 = v3 } - if let v4 = v4 { p4 = v4 } - if let v5 = v5 { p5 = v5 } - if let v6 = v6 { p6 = v6 } - if let v7 = v7 { p7 = v7 } - if let v8 = v8 { p8 = v8 } - } - if v1 != nil || v2 != nil || v3 != nil || v4 != nil || v5 != nil || v6 != nil || v7 != nil || v8 != nil, - let c1 = v1 ?? p1, - let c2 = v2 ?? p2, - let c3 = v3 ?? p3, - let c4 = v4 ?? p4, - let c5 = v5 ?? p5, - let c6 = v6 ?? p6, - let c7 = v7 ?? p7, - let c8 = v8 ?? p8 - { - return (c1, c2, c3, c4, c5, c6, c7, c8) - } else { - return nil - } - } - } -} - -extension ValueObservation where Reducer == ValueReducers.Auto { - public static func combine< - R1: _ValueReducer, - R2: _ValueReducer, - R3: _ValueReducer, - R4: _ValueReducer, - R5: _ValueReducer, - R6: _ValueReducer, - R7: _ValueReducer, - R8: _ValueReducer>( - _ o1: ValueObservation, - _ o2: ValueObservation, - _ o3: ValueObservation, - _ o4: ValueObservation, - _ o5: ValueObservation, - _ o6: ValueObservation, - _ o7: ValueObservation, - _ o8: ValueObservation) - -> ValueObservation> - { - return ValueObservation( - makeReducer: { ValueReducers.Combine8( - o1.makeReducer(), - o2.makeReducer(), - o3.makeReducer(), - o4.makeReducer(), - o5.makeReducer(), - o6.makeReducer(), - o7.makeReducer(), - o8.makeReducer()) }, - requiresWriteAccess: o1.requiresWriteAccess - || o2.requiresWriteAccess - || o3.requiresWriteAccess - || o4.requiresWriteAccess - || o5.requiresWriteAccess - || o6.requiresWriteAccess - || o7.requiresWriteAccess - || o8.requiresWriteAccess) - } -} diff --git a/GRDBCustom.xcodeproj/project.pbxproj b/GRDBCustom.xcodeproj/project.pbxproj index 1dd1708b1..f085ef88f 100755 --- a/GRDBCustom.xcodeproj/project.pbxproj +++ b/GRDBCustom.xcodeproj/project.pbxproj @@ -20,8 +20,6 @@ 56071A501DB54ED300CA6E47 /* FetchedRecordsControllerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B15D0A1CD4C35100A24C8B /* FetchedRecordsControllerTests.swift */; }; 5613ED6121A95E6100DC7A68 /* ValueObservation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5613ED5921A95E6100DC7A68 /* ValueObservation.swift */; }; 5613ED6221A95E6100DC7A68 /* ValueObservation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5613ED5921A95E6100DC7A68 /* ValueObservation.swift */; }; - 5613EDA321A96A8100DC7A68 /* ValueObservationCombineTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5613EDA221A96A8000DC7A68 /* ValueObservationCombineTests.swift */; }; - 5613EDA421A96A8100DC7A68 /* ValueObservationCombineTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5613EDA221A96A8000DC7A68 /* ValueObservationCombineTests.swift */; }; 561408A0221596A100DAD589 /* GRDB-5.0.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5614089E221596A100DAD589 /* GRDB-5.0.swift */; }; 561408A1221596A100DAD589 /* GRDB-5.0.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5614089E221596A100DAD589 /* GRDB-5.0.swift */; }; 5615B258222AE19100061C1C /* AssociationHasOneThroughSQLDerivationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5615B256222AE19100061C1C /* AssociationHasOneThroughSQLDerivationTests.swift */; }; @@ -417,8 +415,6 @@ 56C0539422ACEECD0029D27D /* Fetch.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56C0538A22ACEECD0029D27D /* Fetch.swift */; }; 56C0539722ACEECD0029D27D /* ValueReducer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56C0538C22ACEECD0029D27D /* ValueReducer.swift */; }; 56C0539822ACEECD0029D27D /* ValueReducer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56C0538C22ACEECD0029D27D /* ValueReducer.swift */; }; - 56C0539922ACEECD0029D27D /* Combine.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56C0538D22ACEECD0029D27D /* Combine.swift */; }; - 56C0539A22ACEECD0029D27D /* Combine.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56C0538D22ACEECD0029D27D /* Combine.swift */; }; 56C0539B22ACEECD0029D27D /* Map.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56C0538E22ACEECD0029D27D /* Map.swift */; }; 56C0539C22ACEECD0029D27D /* Map.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56C0538E22ACEECD0029D27D /* Map.swift */; }; 56C0539D22ACEECD0029D27D /* RemoveDuplicates.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56C0538F22ACEECD0029D27D /* RemoveDuplicates.swift */; }; @@ -735,7 +731,6 @@ 560D92441C672C4B00F4F92B /* PersistableRecord.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PersistableRecord.swift; sourceTree = ""; }; 560D92461C672C4B00F4F92B /* TableRecord.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TableRecord.swift; sourceTree = ""; }; 5613ED5921A95E6100DC7A68 /* ValueObservation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ValueObservation.swift; sourceTree = ""; }; - 5613EDA221A96A8000DC7A68 /* ValueObservationCombineTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ValueObservationCombineTests.swift; sourceTree = ""; }; 5614089E221596A100DAD589 /* GRDB-5.0.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "GRDB-5.0.swift"; sourceTree = ""; }; 5615B256222AE19100061C1C /* AssociationHasOneThroughSQLDerivationTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationHasOneThroughSQLDerivationTests.swift; sourceTree = ""; }; 5615B26C222AFEB300061C1C /* AssociationHasOneThroughRowScopeTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationHasOneThroughRowScopeTests.swift; sourceTree = ""; }; @@ -999,7 +994,6 @@ 56BF22862417821F003D86EB /* UtilsTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UtilsTests.swift; sourceTree = ""; }; 56C0538A22ACEECD0029D27D /* Fetch.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Fetch.swift; sourceTree = ""; }; 56C0538C22ACEECD0029D27D /* ValueReducer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ValueReducer.swift; sourceTree = ""; }; - 56C0538D22ACEECD0029D27D /* Combine.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Combine.swift; sourceTree = ""; }; 56C0538E22ACEECD0029D27D /* Map.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Map.swift; sourceTree = ""; }; 56C0538F22ACEECD0029D27D /* RemoveDuplicates.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RemoveDuplicates.swift; sourceTree = ""; }; 56C3F7521CF9F12400F6A361 /* DatabaseSavepointTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseSavepointTests.swift; sourceTree = ""; }; @@ -1315,7 +1309,6 @@ 563B06DB2185E04E00B38F35 /* ValueObservation */ = { isa = PBXGroup; children = ( - 5613EDA221A96A8000DC7A68 /* ValueObservationCombineTests.swift */, 563B06FE21861D9D00B38F35 /* ValueObservationCountTests.swift */, 563B071A21862F5600B38F35 /* ValueObservationDatabaseValueConvertibleTests.swift */, 563B06CE2185E04600B38F35 /* ValueObservationFetchTests.swift */, @@ -1703,7 +1696,6 @@ 56C0538822ACEECD0029D27D /* ValueReducer */ = { isa = PBXGroup; children = ( - 56C0538D22ACEECD0029D27D /* Combine.swift */, 56C0538A22ACEECD0029D27D /* Fetch.swift */, 56C0538E22ACEECD0029D27D /* Map.swift */, 56C0538F22ACEECD0029D27D /* RemoveDuplicates.swift */, @@ -2182,7 +2174,6 @@ F3BA80101CFB2876003DC1BA /* DatabaseReader.swift in Sources */, 564F9C331F07611800877A00 /* DatabaseFunction.swift in Sources */, 5656A8942295BD56001FF3FF /* SQLFunctions.swift in Sources */, - 56C0539A22ACEECD0029D27D /* Combine.swift in Sources */, 5659F49D1EA8D989004A4992 /* Pool.swift in Sources */, 563A4B72242E7CE60075D8CF /* ValueObservationScheduler.swift in Sources */, 5674A6F61F307F600095F066 /* EncodableRecord+Encodable.swift in Sources */, @@ -2381,7 +2372,6 @@ 5653EB6920961FB200F46237 /* AssociationParallelSQLTests.swift in Sources */, F3BA80B71CFB2FCD003DC1BA /* DatabaseErrorTests.swift in Sources */, 5698ACCC1DA62A2D0056AF8C /* FTS5TokenizerTests.swift in Sources */, - 5613EDA421A96A8100DC7A68 /* ValueObservationCombineTests.swift in Sources */, 5653EB6B20961FB200F46237 /* AssociationBelongsToFetchableRecordTests.swift in Sources */, 560432A7228F167A009D3FE2 /* AssociationPrefetchingObservationTests.swift in Sources */, 5690C33E1D23E7D200E59934 /* FoundationDateTests.swift in Sources */, @@ -2518,7 +2508,6 @@ F3BA806C1CFB2E55003DC1BA /* DatabaseReader.swift in Sources */, 564F9C301F07611500877A00 /* DatabaseFunction.swift in Sources */, 5656A8932295BD56001FF3FF /* SQLFunctions.swift in Sources */, - 56C0539922ACEECD0029D27D /* Combine.swift in Sources */, 5659F49A1EA8D989004A4992 /* Pool.swift in Sources */, 563A4B71242E7CE60075D8CF /* ValueObservationScheduler.swift in Sources */, 5674A6F51F307F600095F066 /* EncodableRecord+Encodable.swift in Sources */, @@ -2717,7 +2706,6 @@ 5653EB6820961FB200F46237 /* AssociationParallelSQLTests.swift in Sources */, F3BA80F21CFB301A003DC1BA /* DatabaseSavepointTests.swift in Sources */, F3BA80B81CFB2FCD003DC1BA /* DatabaseErrorTests.swift in Sources */, - 5613EDA321A96A8100DC7A68 /* ValueObservationCombineTests.swift in Sources */, 5653EB6A20961FB200F46237 /* AssociationBelongsToFetchableRecordTests.swift in Sources */, 560432A6228F167A009D3FE2 /* AssociationPrefetchingObservationTests.swift in Sources */, 5698AC061D9B9FCF0056AF8C /* QueryInterfaceExtensibilityTests.swift in Sources */, diff --git a/README.md b/README.md index dcea41ca4..fd1bebc08 100644 --- a/README.md +++ b/README.md @@ -5711,7 +5711,6 @@ let cancellable = observation.start( - [ValueObservation.map](#valueobservationmap) - [ValueObservation.removeDuplicates](#valueobservationremoveduplicates) -- [ValueObservation.combine](#valueobservationcombine) - [ValueObservation.requiresWriteAccess](#valueobservationrequireswriteaccess) @@ -5772,49 +5771,6 @@ let observation = ValueObservation ``` -#### ValueObservation.combine - -The `ValueObservation.combine` static method builds a single observation from several (up to eight): - -```swift -// An observation of Int -let playerCountObservation = ValueObservation.tracking { db in - try Player.fetchCount(db) -} -// An observation of [Player] -let bestPlayersObservation = ValueObservation.tracking { db in - try Player - .limit(10) - .order(Column("score").desc) - .fetchAll(db) -} - -// The combined observation of (Int, [Player]) -let observation = ValueObservation.combine( - playerCountObservation, - bestPlayersObservation) -``` - -Combining observations together provides the guarantee that notified values are [**consistent**](https://en.wikipedia.org/wiki/Consistency_(database_systems)). - -`combine` also exists as an instance method: - -```swift -struct HallOfFame { - var totalPlayerCount: Int - var bestPlayers: [Player] -} - -// An observation of HallOfFame -let observation = playerCountObservation.combine(bestPlayersObservation) { - HallOfFame(totalPlayerCount: $0, bestPlayers: $1) -} -``` - - -> :point_up: **Note**: readers who are familiar with Reactive Programming will recognize the [CombineLatest](http://reactivex.io/documentation/operators/combinelatest.html) operator in the ValueObservation `combine` method. This is partially exact, because the reactive operator is unable to guarantee data consistency. If you use a Reactive layer such as [GRDBCombine] or [RxGRDB], make sure you compose observations with `ValueObservation.combine`, and never with the CombineLatest operator. - - #### ValueObservation.requiresWriteAccess The `requiresWriteAccess` property is false by default. When true, a ValueObservation has a write access to the database, and its fetches are automatically wrapped in a [savepoint](#transactions-and-savepoints): diff --git a/Tests/CocoaPods/SQLCipher3/GRDBTests.xcodeproj/project.pbxproj b/Tests/CocoaPods/SQLCipher3/GRDBTests.xcodeproj/project.pbxproj index 82c508f51..013b0f508 100644 --- a/Tests/CocoaPods/SQLCipher3/GRDBTests.xcodeproj/project.pbxproj +++ b/Tests/CocoaPods/SQLCipher3/GRDBTests.xcodeproj/project.pbxproj @@ -165,7 +165,6 @@ 564A206A226B89E1001F64F1 /* FoundationNSStringTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FB3226B89DC001F64F1 /* FoundationNSStringTests.swift */; }; 564A206B226B89E1001F64F1 /* AssociationHasManyThroughSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FB4226B89DD001F64F1 /* AssociationHasManyThroughSQLTests.swift */; }; 564A206C226B89E1001F64F1 /* FTS5CustomTokenizerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FB5226B89DD001F64F1 /* FTS5CustomTokenizerTests.swift */; }; - 564A206D226B89E1001F64F1 /* ValueObservationCombineTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FB6226B89DD001F64F1 /* ValueObservationCombineTests.swift */; }; 564A206F226B89E1001F64F1 /* MapCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FB8226B89DD001F64F1 /* MapCursorTests.swift */; }; 564A2071226B89E1001F64F1 /* VirtualTableModuleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FBA226B89DD001F64F1 /* VirtualTableModuleTests.swift */; }; 564A2072226B89E1001F64F1 /* DropFirstCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FBB226B89DD001F64F1 /* DropFirstCursorTests.swift */; }; @@ -363,7 +362,6 @@ 564A2139226B8E18001F64F1 /* AssociationParallelDecodableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F70226B89D6001F64F1 /* AssociationParallelDecodableRecordTests.swift */; }; 564A213A226B8E18001F64F1 /* AssociationBelongsToDecodableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F35226B89CF001F64F1 /* AssociationBelongsToDecodableRecordTests.swift */; }; 564A213B226B8E18001F64F1 /* DatabaseMigratorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FD4226B89E0001F64F1 /* DatabaseMigratorTests.swift */; }; - 564A213C226B8E18001F64F1 /* ValueObservationCombineTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FB6226B89DD001F64F1 /* ValueObservationCombineTests.swift */; }; 564A213D226B8E18001F64F1 /* CursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F6B226B89D5001F64F1 /* CursorTests.swift */; }; 564A213E226B8E18001F64F1 /* DatabaseDateDecodingStrategyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F83226B89D8001F64F1 /* DatabaseDateDecodingStrategyTests.swift */; }; 564A213F226B8E18001F64F1 /* SchedulingWatchdogTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F7F226B89D7001F64F1 /* SchedulingWatchdogTests.swift */; }; @@ -563,7 +561,6 @@ 564A1FB3226B89DC001F64F1 /* FoundationNSStringTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FoundationNSStringTests.swift; sourceTree = ""; }; 564A1FB4226B89DD001F64F1 /* AssociationHasManyThroughSQLTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationHasManyThroughSQLTests.swift; sourceTree = ""; }; 564A1FB5226B89DD001F64F1 /* FTS5CustomTokenizerTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS5CustomTokenizerTests.swift; sourceTree = ""; }; - 564A1FB6226B89DD001F64F1 /* ValueObservationCombineTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ValueObservationCombineTests.swift; sourceTree = ""; }; 564A1FB8226B89DD001F64F1 /* MapCursorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MapCursorTests.swift; sourceTree = ""; }; 564A1FBA226B89DD001F64F1 /* VirtualTableModuleTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VirtualTableModuleTests.swift; sourceTree = ""; }; 564A1FBB226B89DD001F64F1 /* DropFirstCursorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DropFirstCursorTests.swift; sourceTree = ""; }; @@ -848,7 +845,6 @@ 564A1FCA226B89DF001F64F1 /* TransactionObserverTests.swift */, 564A1F3C226B89D0001F64F1 /* TruncateOptimizationTests.swift */, 564A1FBD226B89DE001F64F1 /* UpdateStatementTests.swift */, - 564A1FB6226B89DD001F64F1 /* ValueObservationCombineTests.swift */, 564A1F84226B89D8001F64F1 /* ValueObservationCountTests.swift */, 564A1F6C226B89D5001F64F1 /* ValueObservationDatabaseValueConvertibleTests.swift */, 564A1FC6226B89DF001F64F1 /* ValueObservationFetchTests.swift */, @@ -1248,7 +1244,6 @@ 564A2027226B89E1001F64F1 /* AssociationParallelDecodableRecordTests.swift in Sources */, 564A1FEC226B89E1001F64F1 /* AssociationBelongsToDecodableRecordTests.swift in Sources */, 564A208B226B89E1001F64F1 /* DatabaseMigratorTests.swift in Sources */, - 564A206D226B89E1001F64F1 /* ValueObservationCombineTests.swift in Sources */, 564A2022226B89E1001F64F1 /* CursorTests.swift in Sources */, 564A203A226B89E1001F64F1 /* DatabaseDateDecodingStrategyTests.swift in Sources */, 56E4F7FF2392E6D200A611F6 /* DatabaseAbortedTransactionTests.swift in Sources */, @@ -1452,7 +1447,6 @@ 564A2139226B8E18001F64F1 /* AssociationParallelDecodableRecordTests.swift in Sources */, 564A213A226B8E18001F64F1 /* AssociationBelongsToDecodableRecordTests.swift in Sources */, 564A213B226B8E18001F64F1 /* DatabaseMigratorTests.swift in Sources */, - 564A213C226B8E18001F64F1 /* ValueObservationCombineTests.swift in Sources */, 564A213D226B8E18001F64F1 /* CursorTests.swift in Sources */, 564A213E226B8E18001F64F1 /* DatabaseDateDecodingStrategyTests.swift in Sources */, 56E4F8002392E6D200A611F6 /* DatabaseAbortedTransactionTests.swift in Sources */, diff --git a/Tests/CocoaPods/SQLCipher4/GRDBTests.xcodeproj/project.pbxproj b/Tests/CocoaPods/SQLCipher4/GRDBTests.xcodeproj/project.pbxproj index e20e802d7..fde19adfd 100644 --- a/Tests/CocoaPods/SQLCipher4/GRDBTests.xcodeproj/project.pbxproj +++ b/Tests/CocoaPods/SQLCipher4/GRDBTests.xcodeproj/project.pbxproj @@ -165,7 +165,6 @@ 564A206A226B89E1001F64F1 /* FoundationNSStringTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FB3226B89DC001F64F1 /* FoundationNSStringTests.swift */; }; 564A206B226B89E1001F64F1 /* AssociationHasManyThroughSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FB4226B89DD001F64F1 /* AssociationHasManyThroughSQLTests.swift */; }; 564A206C226B89E1001F64F1 /* FTS5CustomTokenizerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FB5226B89DD001F64F1 /* FTS5CustomTokenizerTests.swift */; }; - 564A206D226B89E1001F64F1 /* ValueObservationCombineTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FB6226B89DD001F64F1 /* ValueObservationCombineTests.swift */; }; 564A206F226B89E1001F64F1 /* MapCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FB8226B89DD001F64F1 /* MapCursorTests.swift */; }; 564A2071226B89E1001F64F1 /* VirtualTableModuleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FBA226B89DD001F64F1 /* VirtualTableModuleTests.swift */; }; 564A2072226B89E1001F64F1 /* DropFirstCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FBB226B89DD001F64F1 /* DropFirstCursorTests.swift */; }; @@ -363,7 +362,6 @@ 564A2139226B8E18001F64F1 /* AssociationParallelDecodableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F70226B89D6001F64F1 /* AssociationParallelDecodableRecordTests.swift */; }; 564A213A226B8E18001F64F1 /* AssociationBelongsToDecodableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F35226B89CF001F64F1 /* AssociationBelongsToDecodableRecordTests.swift */; }; 564A213B226B8E18001F64F1 /* DatabaseMigratorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FD4226B89E0001F64F1 /* DatabaseMigratorTests.swift */; }; - 564A213C226B8E18001F64F1 /* ValueObservationCombineTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1FB6226B89DD001F64F1 /* ValueObservationCombineTests.swift */; }; 564A213D226B8E18001F64F1 /* CursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F6B226B89D5001F64F1 /* CursorTests.swift */; }; 564A213E226B8E18001F64F1 /* DatabaseDateDecodingStrategyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F83226B89D8001F64F1 /* DatabaseDateDecodingStrategyTests.swift */; }; 564A213F226B8E18001F64F1 /* SchedulingWatchdogTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F7F226B89D7001F64F1 /* SchedulingWatchdogTests.swift */; }; @@ -565,7 +563,6 @@ 564A1FB3226B89DC001F64F1 /* FoundationNSStringTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FoundationNSStringTests.swift; sourceTree = ""; }; 564A1FB4226B89DD001F64F1 /* AssociationHasManyThroughSQLTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationHasManyThroughSQLTests.swift; sourceTree = ""; }; 564A1FB5226B89DD001F64F1 /* FTS5CustomTokenizerTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS5CustomTokenizerTests.swift; sourceTree = ""; }; - 564A1FB6226B89DD001F64F1 /* ValueObservationCombineTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ValueObservationCombineTests.swift; sourceTree = ""; }; 564A1FB8226B89DD001F64F1 /* MapCursorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MapCursorTests.swift; sourceTree = ""; }; 564A1FBA226B89DD001F64F1 /* VirtualTableModuleTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VirtualTableModuleTests.swift; sourceTree = ""; }; 564A1FBB226B89DD001F64F1 /* DropFirstCursorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DropFirstCursorTests.swift; sourceTree = ""; }; @@ -852,7 +849,6 @@ 564A1FCA226B89DF001F64F1 /* TransactionObserverTests.swift */, 564A1F3C226B89D0001F64F1 /* TruncateOptimizationTests.swift */, 564A1FBD226B89DE001F64F1 /* UpdateStatementTests.swift */, - 564A1FB6226B89DD001F64F1 /* ValueObservationCombineTests.swift */, 564A1F84226B89D8001F64F1 /* ValueObservationCountTests.swift */, 564A1F6C226B89D5001F64F1 /* ValueObservationDatabaseValueConvertibleTests.swift */, 564A1FC6226B89DF001F64F1 /* ValueObservationFetchTests.swift */, @@ -1253,7 +1249,6 @@ 564A2027226B89E1001F64F1 /* AssociationParallelDecodableRecordTests.swift in Sources */, 564A1FEC226B89E1001F64F1 /* AssociationBelongsToDecodableRecordTests.swift in Sources */, 564A208B226B89E1001F64F1 /* DatabaseMigratorTests.swift in Sources */, - 564A206D226B89E1001F64F1 /* ValueObservationCombineTests.swift in Sources */, 564A2022226B89E1001F64F1 /* CursorTests.swift in Sources */, 564A203A226B89E1001F64F1 /* DatabaseDateDecodingStrategyTests.swift in Sources */, 564A2036226B89E1001F64F1 /* SchedulingWatchdogTests.swift in Sources */, @@ -1457,7 +1452,6 @@ 564A2139226B8E18001F64F1 /* AssociationParallelDecodableRecordTests.swift in Sources */, 564A213A226B8E18001F64F1 /* AssociationBelongsToDecodableRecordTests.swift in Sources */, 564A213B226B8E18001F64F1 /* DatabaseMigratorTests.swift in Sources */, - 564A213C226B8E18001F64F1 /* ValueObservationCombineTests.swift in Sources */, 564A213D226B8E18001F64F1 /* CursorTests.swift in Sources */, 564A213E226B8E18001F64F1 /* DatabaseDateDecodingStrategyTests.swift in Sources */, 564A213F226B8E18001F64F1 /* SchedulingWatchdogTests.swift in Sources */, diff --git a/Tests/GRDBTests/ValueObservationCombineTests.swift b/Tests/GRDBTests/ValueObservationCombineTests.swift deleted file mode 100644 index 2dd542bb7..000000000 --- a/Tests/GRDBTests/ValueObservationCombineTests.swift +++ /dev/null @@ -1,878 +0,0 @@ -import XCTest -#if GRDBCIPHER -import SQLCipher -#elseif SWIFT_PACKAGE -import CSQLite -#elseif !GRDBCUSTOMSQLITE -import SQLite3 -#endif -import GRDB - -class ValueObservationCombineTests: GRDBTestCase { - func testCombine2() throws { - let dbQueue = try makeDatabaseQueue() - try dbQueue.write { - try $0.execute(sql: """ - CREATE TABLE t1(id INTEGER PRIMARY KEY AUTOINCREMENT); - CREATE TABLE t2(id INTEGER PRIMARY KEY AUTOINCREMENT); - """) - } - - struct T1: TableRecord { } - struct T2: TableRecord { } - let observation1 = ValueObservation.tracking(T1.fetchCount).removeDuplicates() - let observation2 = ValueObservation.tracking(T2.fetchCount).removeDuplicates() - let observation = ValueObservation.combine(observation1, observation2) - let recorder = observation.record(in: dbQueue) - - try dbQueue.write { db in - try db.execute(sql: "INSERT INTO t1 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute(sql: "INSERT INTO t2 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute(sql: "DELETE FROM t1") - try db.execute(sql: "INSERT INTO t1 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute(sql: "DELETE FROM t2") - try db.execute(sql: "INSERT INTO t2 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute(sql: "DELETE FROM t1") - try db.execute(sql: "DELETE FROM t2") - try db.execute(sql: "INSERT INTO t1 DEFAULT VALUES") - try db.execute(sql: "INSERT INTO t2 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute(sql: "INSERT INTO t1 DEFAULT VALUES") - try db.execute(sql: "INSERT INTO t2 DEFAULT VALUES") - } - - let expectedValues = [ - [0, 0], - [1, 0], - [1, 1], - [2, 2]] - let values = try wait(for: recorder.next(expectedValues.count), timeout: 0.5) - XCTAssertEqual(values.map { [$0, $1] }, expectedValues) - } - - func testCombine3() throws { - let dbQueue = try makeDatabaseQueue() - try dbQueue.write { - try $0.execute(sql: """ - CREATE TABLE t1(id INTEGER PRIMARY KEY AUTOINCREMENT); - CREATE TABLE t2(id INTEGER PRIMARY KEY AUTOINCREMENT); - CREATE TABLE t3(id INTEGER PRIMARY KEY AUTOINCREMENT); - """) - } - - struct T1: TableRecord { } - struct T2: TableRecord { } - struct T3: TableRecord { } - let observation1 = ValueObservation.tracking(T1.fetchCount).removeDuplicates() - let observation2 = ValueObservation.tracking(T2.fetchCount).removeDuplicates() - let observation3 = ValueObservation.tracking(T3.fetchCount).removeDuplicates() - let observation = ValueObservation.combine(observation1, observation2, observation3) - let recorder = observation.record(in: dbQueue) - - try dbQueue.write { db in - try db.execute(sql: "INSERT INTO t1 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute(sql: "INSERT INTO t2 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute(sql: "INSERT INTO t3 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute(sql: "DELETE FROM t1") - try db.execute(sql: "INSERT INTO t1 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute(sql: "DELETE FROM t2") - try db.execute(sql: "INSERT INTO t2 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute(sql: "DELETE FROM t3") - try db.execute(sql: "INSERT INTO t3 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute(sql: "DELETE FROM t1") - try db.execute(sql: "DELETE FROM t2") - try db.execute(sql: "DELETE FROM t3") - try db.execute(sql: "INSERT INTO t1 DEFAULT VALUES") - try db.execute(sql: "INSERT INTO t2 DEFAULT VALUES") - try db.execute(sql: "INSERT INTO t3 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute(sql: "INSERT INTO t1 DEFAULT VALUES") - try db.execute(sql: "INSERT INTO t2 DEFAULT VALUES") - try db.execute(sql: "INSERT INTO t3 DEFAULT VALUES") - } - - let expectedValues = [ - [0, 0, 0], - [1, 0, 0], - [1, 1, 0], - [1, 1, 1], - [2, 2, 2]] - let values = try wait(for: recorder.next(expectedValues.count), timeout: 0.5) - XCTAssertEqual(values.map { [$0, $1, $2] }, expectedValues) - } - - func testCombine4() throws { - let dbQueue = try makeDatabaseQueue() - try dbQueue.write { - try $0.execute(sql: """ - CREATE TABLE t1(id INTEGER PRIMARY KEY AUTOINCREMENT); - CREATE TABLE t2(id INTEGER PRIMARY KEY AUTOINCREMENT); - CREATE TABLE t3(id INTEGER PRIMARY KEY AUTOINCREMENT); - CREATE TABLE t4(id INTEGER PRIMARY KEY AUTOINCREMENT); - """) - } - - struct T1: TableRecord { } - struct T2: TableRecord { } - struct T3: TableRecord { } - struct T4: TableRecord { } - let observation1 = ValueObservation.tracking(T1.fetchCount).removeDuplicates() - let observation2 = ValueObservation.tracking(T2.fetchCount).removeDuplicates() - let observation3 = ValueObservation.tracking(T3.fetchCount).removeDuplicates() - let observation4 = ValueObservation.tracking(T4.fetchCount).removeDuplicates() - let observation = ValueObservation.combine(observation1, observation2, observation3, observation4) - let recorder = observation.record(in: dbQueue) - - try dbQueue.write { db in - try db.execute(sql: "INSERT INTO t1 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute(sql: "INSERT INTO t2 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute(sql: "INSERT INTO t3 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute(sql: "INSERT INTO t4 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute(sql: "DELETE FROM t1") - try db.execute(sql: "INSERT INTO t1 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute(sql: "DELETE FROM t2") - try db.execute(sql: "INSERT INTO t2 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute(sql: "DELETE FROM t3") - try db.execute(sql: "INSERT INTO t3 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute(sql: "DELETE FROM t4") - try db.execute(sql: "INSERT INTO t4 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute(sql: "DELETE FROM t1") - try db.execute(sql: "DELETE FROM t2") - try db.execute(sql: "DELETE FROM t3") - try db.execute(sql: "DELETE FROM t4") - try db.execute(sql: "INSERT INTO t1 DEFAULT VALUES") - try db.execute(sql: "INSERT INTO t2 DEFAULT VALUES") - try db.execute(sql: "INSERT INTO t3 DEFAULT VALUES") - try db.execute(sql: "INSERT INTO t4 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute(sql: "INSERT INTO t1 DEFAULT VALUES") - try db.execute(sql: "INSERT INTO t2 DEFAULT VALUES") - try db.execute(sql: "INSERT INTO t3 DEFAULT VALUES") - try db.execute(sql: "INSERT INTO t4 DEFAULT VALUES") - } - - let expectedValues = [ - [0, 0, 0, 0], - [1, 0, 0, 0], - [1, 1, 0, 0], - [1, 1, 1, 0], - [1, 1, 1, 1], - [2, 2, 2, 2]] - let values = try wait(for: recorder.next(expectedValues.count), timeout: 0.5) - XCTAssertEqual(values.map { [$0, $1, $2, $3] }, expectedValues) - } - - func testCombine5() throws { - let dbQueue = try makeDatabaseQueue() - try dbQueue.write { - try $0.execute(sql: """ - CREATE TABLE t1(id INTEGER PRIMARY KEY AUTOINCREMENT); - CREATE TABLE t2(id INTEGER PRIMARY KEY AUTOINCREMENT); - CREATE TABLE t3(id INTEGER PRIMARY KEY AUTOINCREMENT); - CREATE TABLE t4(id INTEGER PRIMARY KEY AUTOINCREMENT); - CREATE TABLE t5(id INTEGER PRIMARY KEY AUTOINCREMENT); - """) - } - - struct T1: TableRecord { } - struct T2: TableRecord { } - struct T3: TableRecord { } - struct T4: TableRecord { } - struct T5: TableRecord { } - let observation1 = ValueObservation.tracking(T1.fetchCount).removeDuplicates() - let observation2 = ValueObservation.tracking(T2.fetchCount).removeDuplicates() - let observation3 = ValueObservation.tracking(T3.fetchCount).removeDuplicates() - let observation4 = ValueObservation.tracking(T4.fetchCount).removeDuplicates() - let observation5 = ValueObservation.tracking(T5.fetchCount).removeDuplicates() - let observation = ValueObservation.combine(observation1, observation2, observation3, observation4, observation5) - let recorder = observation.record(in: dbQueue) - - try dbQueue.write { db in - try db.execute(sql: "INSERT INTO t1 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute(sql: "INSERT INTO t2 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute(sql: "INSERT INTO t3 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute(sql: "INSERT INTO t4 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute(sql: "INSERT INTO t5 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute(sql: "DELETE FROM t1") - try db.execute(sql: "INSERT INTO t1 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute(sql: "DELETE FROM t2") - try db.execute(sql: "INSERT INTO t2 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute(sql: "DELETE FROM t3") - try db.execute(sql: "INSERT INTO t3 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute(sql: "DELETE FROM t4") - try db.execute(sql: "INSERT INTO t4 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute(sql: "DELETE FROM t5") - try db.execute(sql: "INSERT INTO t5 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute(sql: "DELETE FROM t1") - try db.execute(sql: "DELETE FROM t2") - try db.execute(sql: "DELETE FROM t3") - try db.execute(sql: "DELETE FROM t4") - try db.execute(sql: "DELETE FROM t5") - try db.execute(sql: "INSERT INTO t1 DEFAULT VALUES") - try db.execute(sql: "INSERT INTO t2 DEFAULT VALUES") - try db.execute(sql: "INSERT INTO t3 DEFAULT VALUES") - try db.execute(sql: "INSERT INTO t4 DEFAULT VALUES") - try db.execute(sql: "INSERT INTO t5 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute(sql: "INSERT INTO t1 DEFAULT VALUES") - try db.execute(sql: "INSERT INTO t2 DEFAULT VALUES") - try db.execute(sql: "INSERT INTO t3 DEFAULT VALUES") - try db.execute(sql: "INSERT INTO t4 DEFAULT VALUES") - try db.execute(sql: "INSERT INTO t5 DEFAULT VALUES") - } - - let expectedValues = [ - [0, 0, 0, 0, 0], - [1, 0, 0, 0, 0], - [1, 1, 0, 0, 0], - [1, 1, 1, 0, 0], - [1, 1, 1, 1, 0], - [1, 1, 1, 1, 1], - [2, 2, 2, 2, 2]] - let values = try wait(for: recorder.next(expectedValues.count), timeout: 0.5) - XCTAssertEqual(values.map { [$0, $1, $2, $3, $4] }, expectedValues) - } - - func testCombine6() throws { - let dbQueue = try makeDatabaseQueue() - try dbQueue.write { - try $0.execute(sql: """ - CREATE TABLE t1(id INTEGER PRIMARY KEY AUTOINCREMENT); - CREATE TABLE t2(id INTEGER PRIMARY KEY AUTOINCREMENT); - CREATE TABLE t3(id INTEGER PRIMARY KEY AUTOINCREMENT); - CREATE TABLE t4(id INTEGER PRIMARY KEY AUTOINCREMENT); - CREATE TABLE t5(id INTEGER PRIMARY KEY AUTOINCREMENT); - CREATE TABLE t6(id INTEGER PRIMARY KEY AUTOINCREMENT); - """) - } - - struct T1: TableRecord { } - struct T2: TableRecord { } - struct T3: TableRecord { } - struct T4: TableRecord { } - struct T5: TableRecord { } - struct T6: TableRecord { } - let observation1 = ValueObservation.tracking(T1.fetchCount).removeDuplicates() - let observation2 = ValueObservation.tracking(T2.fetchCount).removeDuplicates() - let observation3 = ValueObservation.tracking(T3.fetchCount).removeDuplicates() - let observation4 = ValueObservation.tracking(T4.fetchCount).removeDuplicates() - let observation5 = ValueObservation.tracking(T5.fetchCount).removeDuplicates() - let observation6 = ValueObservation.tracking(T6.fetchCount).removeDuplicates() - let observation = ValueObservation.combine(observation1, observation2, observation3, observation4, observation5, observation6) - let recorder = observation.record(in: dbQueue) - - try dbQueue.write { db in - try db.execute(sql: "INSERT INTO t1 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute(sql: "INSERT INTO t2 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute(sql: "INSERT INTO t3 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute(sql: "INSERT INTO t4 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute(sql: "INSERT INTO t5 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute(sql: "INSERT INTO t6 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute(sql: "DELETE FROM t1") - try db.execute(sql: "INSERT INTO t1 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute(sql: "DELETE FROM t2") - try db.execute(sql: "INSERT INTO t2 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute(sql: "DELETE FROM t3") - try db.execute(sql: "INSERT INTO t3 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute(sql: "DELETE FROM t4") - try db.execute(sql: "INSERT INTO t4 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute(sql: "DELETE FROM t5") - try db.execute(sql: "INSERT INTO t5 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute(sql: "DELETE FROM t6") - try db.execute(sql: "INSERT INTO t6 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute(sql: "DELETE FROM t1") - try db.execute(sql: "DELETE FROM t2") - try db.execute(sql: "DELETE FROM t3") - try db.execute(sql: "DELETE FROM t4") - try db.execute(sql: "DELETE FROM t5") - try db.execute(sql: "DELETE FROM t6") - try db.execute(sql: "INSERT INTO t1 DEFAULT VALUES") - try db.execute(sql: "INSERT INTO t2 DEFAULT VALUES") - try db.execute(sql: "INSERT INTO t3 DEFAULT VALUES") - try db.execute(sql: "INSERT INTO t4 DEFAULT VALUES") - try db.execute(sql: "INSERT INTO t5 DEFAULT VALUES") - try db.execute(sql: "INSERT INTO t6 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute(sql: "INSERT INTO t1 DEFAULT VALUES") - try db.execute(sql: "INSERT INTO t2 DEFAULT VALUES") - try db.execute(sql: "INSERT INTO t3 DEFAULT VALUES") - try db.execute(sql: "INSERT INTO t4 DEFAULT VALUES") - try db.execute(sql: "INSERT INTO t5 DEFAULT VALUES") - try db.execute(sql: "INSERT INTO t6 DEFAULT VALUES") - } - - let expectedValues = [ - [0, 0, 0, 0, 0, 0], - [1, 0, 0, 0, 0, 0], - [1, 1, 0, 0, 0, 0], - [1, 1, 1, 0, 0, 0], - [1, 1, 1, 1, 0, 0], - [1, 1, 1, 1, 1, 0], - [1, 1, 1, 1, 1, 1], - [2, 2, 2, 2, 2, 2]] - let values = try wait(for: recorder.next(expectedValues.count), timeout: 0.5) - XCTAssertEqual(values.map { [$0, $1, $2, $3, $4, $5] }, expectedValues) - } - - func testCombine7() throws { - let dbQueue = try makeDatabaseQueue() - try dbQueue.write { - try $0.execute(sql: """ - CREATE TABLE t1(id INTEGER PRIMARY KEY AUTOINCREMENT); - CREATE TABLE t2(id INTEGER PRIMARY KEY AUTOINCREMENT); - CREATE TABLE t3(id INTEGER PRIMARY KEY AUTOINCREMENT); - CREATE TABLE t4(id INTEGER PRIMARY KEY AUTOINCREMENT); - CREATE TABLE t5(id INTEGER PRIMARY KEY AUTOINCREMENT); - CREATE TABLE t6(id INTEGER PRIMARY KEY AUTOINCREMENT); - CREATE TABLE t7(id INTEGER PRIMARY KEY AUTOINCREMENT); - """) - } - - struct T1: TableRecord { } - struct T2: TableRecord { } - struct T3: TableRecord { } - struct T4: TableRecord { } - struct T5: TableRecord { } - struct T6: TableRecord { } - struct T7: TableRecord { } - let observation1 = ValueObservation.tracking(T1.fetchCount).removeDuplicates() - let observation2 = ValueObservation.tracking(T2.fetchCount).removeDuplicates() - let observation3 = ValueObservation.tracking(T3.fetchCount).removeDuplicates() - let observation4 = ValueObservation.tracking(T4.fetchCount).removeDuplicates() - let observation5 = ValueObservation.tracking(T5.fetchCount).removeDuplicates() - let observation6 = ValueObservation.tracking(T6.fetchCount).removeDuplicates() - let observation7 = ValueObservation.tracking(T7.fetchCount).removeDuplicates() - let observation = ValueObservation.combine(observation1, observation2, observation3, observation4, observation5, observation6, observation7) - let recorder = observation.record(in: dbQueue) - - try dbQueue.write { db in - try db.execute(sql: "INSERT INTO t1 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute(sql: "INSERT INTO t2 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute(sql: "INSERT INTO t3 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute(sql: "INSERT INTO t4 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute(sql: "INSERT INTO t5 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute(sql: "INSERT INTO t6 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute(sql: "INSERT INTO t7 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute(sql: "DELETE FROM t1") - try db.execute(sql: "INSERT INTO t1 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute(sql: "DELETE FROM t2") - try db.execute(sql: "INSERT INTO t2 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute(sql: "DELETE FROM t3") - try db.execute(sql: "INSERT INTO t3 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute(sql: "DELETE FROM t4") - try db.execute(sql: "INSERT INTO t4 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute(sql: "DELETE FROM t5") - try db.execute(sql: "INSERT INTO t5 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute(sql: "DELETE FROM t6") - try db.execute(sql: "INSERT INTO t6 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute(sql: "DELETE FROM t7") - try db.execute(sql: "INSERT INTO t7 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute(sql: "DELETE FROM t1") - try db.execute(sql: "DELETE FROM t2") - try db.execute(sql: "DELETE FROM t3") - try db.execute(sql: "DELETE FROM t4") - try db.execute(sql: "DELETE FROM t5") - try db.execute(sql: "DELETE FROM t6") - try db.execute(sql: "DELETE FROM t7") - try db.execute(sql: "INSERT INTO t1 DEFAULT VALUES") - try db.execute(sql: "INSERT INTO t2 DEFAULT VALUES") - try db.execute(sql: "INSERT INTO t3 DEFAULT VALUES") - try db.execute(sql: "INSERT INTO t4 DEFAULT VALUES") - try db.execute(sql: "INSERT INTO t5 DEFAULT VALUES") - try db.execute(sql: "INSERT INTO t6 DEFAULT VALUES") - try db.execute(sql: "INSERT INTO t7 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute(sql: "INSERT INTO t1 DEFAULT VALUES") - try db.execute(sql: "INSERT INTO t2 DEFAULT VALUES") - try db.execute(sql: "INSERT INTO t3 DEFAULT VALUES") - try db.execute(sql: "INSERT INTO t4 DEFAULT VALUES") - try db.execute(sql: "INSERT INTO t5 DEFAULT VALUES") - try db.execute(sql: "INSERT INTO t6 DEFAULT VALUES") - try db.execute(sql: "INSERT INTO t7 DEFAULT VALUES") - } - - let expectedValues = [ - [0, 0, 0, 0, 0, 0, 0], - [1, 0, 0, 0, 0, 0, 0], - [1, 1, 0, 0, 0, 0, 0], - [1, 1, 1, 0, 0, 0, 0], - [1, 1, 1, 1, 0, 0, 0], - [1, 1, 1, 1, 1, 0, 0], - [1, 1, 1, 1, 1, 1, 0], - [1, 1, 1, 1, 1, 1, 1], - [2, 2, 2, 2, 2, 2, 2]] - let values = try wait(for: recorder.next(expectedValues.count), timeout: 0.5) - XCTAssertEqual(values.map { [$0, $1, $2, $3, $4, $5, $6] }, expectedValues) - } - - func testCombine8() throws { - let dbQueue = try makeDatabaseQueue() - try dbQueue.write { - try $0.execute(sql: """ - CREATE TABLE t1(id INTEGER PRIMARY KEY AUTOINCREMENT); - CREATE TABLE t2(id INTEGER PRIMARY KEY AUTOINCREMENT); - CREATE TABLE t3(id INTEGER PRIMARY KEY AUTOINCREMENT); - CREATE TABLE t4(id INTEGER PRIMARY KEY AUTOINCREMENT); - CREATE TABLE t5(id INTEGER PRIMARY KEY AUTOINCREMENT); - CREATE TABLE t6(id INTEGER PRIMARY KEY AUTOINCREMENT); - CREATE TABLE t7(id INTEGER PRIMARY KEY AUTOINCREMENT); - CREATE TABLE t8(id INTEGER PRIMARY KEY AUTOINCREMENT); - """) - } - - struct T1: TableRecord { } - struct T2: TableRecord { } - struct T3: TableRecord { } - struct T4: TableRecord { } - struct T5: TableRecord { } - struct T6: TableRecord { } - struct T7: TableRecord { } - struct T8: TableRecord { } - let observation1 = ValueObservation.tracking(T1.fetchCount).removeDuplicates() - let observation2 = ValueObservation.tracking(T2.fetchCount).removeDuplicates() - let observation3 = ValueObservation.tracking(T3.fetchCount).removeDuplicates() - let observation4 = ValueObservation.tracking(T4.fetchCount).removeDuplicates() - let observation5 = ValueObservation.tracking(T5.fetchCount).removeDuplicates() - let observation6 = ValueObservation.tracking(T6.fetchCount).removeDuplicates() - let observation7 = ValueObservation.tracking(T7.fetchCount).removeDuplicates() - let observation8 = ValueObservation.tracking(T8.fetchCount).removeDuplicates() - let observation = ValueObservation.combine(observation1, observation2, observation3, observation4, observation5, observation6, observation7, observation8) - let recorder = observation.record(in: dbQueue) - - try dbQueue.write { db in - try db.execute(sql: "INSERT INTO t1 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute(sql: "INSERT INTO t2 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute(sql: "INSERT INTO t3 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute(sql: "INSERT INTO t4 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute(sql: "INSERT INTO t5 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute(sql: "INSERT INTO t6 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute(sql: "INSERT INTO t7 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute(sql: "INSERT INTO t8 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute(sql: "DELETE FROM t1") - try db.execute(sql: "INSERT INTO t1 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute(sql: "DELETE FROM t2") - try db.execute(sql: "INSERT INTO t2 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute(sql: "DELETE FROM t3") - try db.execute(sql: "INSERT INTO t3 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute(sql: "DELETE FROM t4") - try db.execute(sql: "INSERT INTO t4 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute(sql: "DELETE FROM t5") - try db.execute(sql: "INSERT INTO t5 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute(sql: "DELETE FROM t6") - try db.execute(sql: "INSERT INTO t6 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute(sql: "DELETE FROM t7") - try db.execute(sql: "INSERT INTO t7 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute(sql: "DELETE FROM t8") - try db.execute(sql: "INSERT INTO t8 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute(sql: "DELETE FROM t1") - try db.execute(sql: "DELETE FROM t2") - try db.execute(sql: "DELETE FROM t3") - try db.execute(sql: "DELETE FROM t4") - try db.execute(sql: "DELETE FROM t5") - try db.execute(sql: "DELETE FROM t6") - try db.execute(sql: "DELETE FROM t7") - try db.execute(sql: "DELETE FROM t8") - try db.execute(sql: "INSERT INTO t1 DEFAULT VALUES") - try db.execute(sql: "INSERT INTO t2 DEFAULT VALUES") - try db.execute(sql: "INSERT INTO t3 DEFAULT VALUES") - try db.execute(sql: "INSERT INTO t4 DEFAULT VALUES") - try db.execute(sql: "INSERT INTO t5 DEFAULT VALUES") - try db.execute(sql: "INSERT INTO t6 DEFAULT VALUES") - try db.execute(sql: "INSERT INTO t7 DEFAULT VALUES") - try db.execute(sql: "INSERT INTO t8 DEFAULT VALUES") - } - try dbQueue.write { db in - try db.execute(sql: "INSERT INTO t1 DEFAULT VALUES") - try db.execute(sql: "INSERT INTO t2 DEFAULT VALUES") - try db.execute(sql: "INSERT INTO t3 DEFAULT VALUES") - try db.execute(sql: "INSERT INTO t4 DEFAULT VALUES") - try db.execute(sql: "INSERT INTO t5 DEFAULT VALUES") - try db.execute(sql: "INSERT INTO t6 DEFAULT VALUES") - try db.execute(sql: "INSERT INTO t7 DEFAULT VALUES") - try db.execute(sql: "INSERT INTO t8 DEFAULT VALUES") - } - - let expectedValues = [ - [0, 0, 0, 0, 0, 0, 0, 0], - [1, 0, 0, 0, 0, 0, 0, 0], - [1, 1, 0, 0, 0, 0, 0, 0], - [1, 1, 1, 0, 0, 0, 0, 0], - [1, 1, 1, 1, 0, 0, 0, 0], - [1, 1, 1, 1, 1, 0, 0, 0], - [1, 1, 1, 1, 1, 1, 0, 0], - [1, 1, 1, 1, 1, 1, 1, 0], - [1, 1, 1, 1, 1, 1, 1, 1], - [2, 2, 2, 2, 2, 2, 2, 2]] - let values = try wait(for: recorder.next(expectedValues.count), timeout: 0.5) - XCTAssertEqual(values.map { [$0, $1, $2, $3, $4, $5, $6, $7] }, expectedValues) - } - - func testHeterogeneusCombine2() throws { - struct V1 { } - struct V2 { } - let observation = ValueObservation.combine( - ValueObservation.tracking { _ in V1() }, - ValueObservation.tracking { _ in V2() }) - var value: (V1, V2)? - _ = try observation.start( - in: makeDatabaseQueue(), - scheduling: .immediate, // So that we can test the fresh value synchronously - onError: { error in XCTFail("Unexpected error: \(error)") }, - onChange: { value = $0 }) - XCTAssertNotNil(value) - } - - func testHeterogeneusCombine3() throws { - struct V1 { } - struct V2 { } - struct V3 { } - let observation = ValueObservation.combine( - ValueObservation.tracking { _ in V1() }, - ValueObservation.tracking { _ in V2() }, - ValueObservation.tracking { _ in V3() }) - var value: (V1, V2, V3)? - _ = try observation.start( - in: makeDatabaseQueue(), - scheduling: .immediate, // So that we can test the fresh value synchronously - onError: { error in XCTFail("Unexpected error: \(error)") }, - onChange: { value = $0 }) - XCTAssertNotNil(value) - } - - func testHeterogeneusCombine4() throws { - struct V1 { } - struct V2 { } - struct V3 { } - struct V4 { } - let observation = ValueObservation.combine( - ValueObservation.tracking { _ in V1() }, - ValueObservation.tracking { _ in V2() }, - ValueObservation.tracking { _ in V3() }, - ValueObservation.tracking { _ in V4() }) - var value: (V1, V2, V3, V4)? - _ = try observation.start( - in: makeDatabaseQueue(), - scheduling: .immediate, // So that we can test the fresh value synchronously - onError: { error in XCTFail("Unexpected error: \(error)") }, - onChange: { value = $0 }) - XCTAssertNotNil(value) - } - - func testHeterogeneusCombine5() throws { - struct V1 { } - struct V2 { } - struct V3 { } - struct V4 { } - struct V5 { } - let observation = ValueObservation.combine( - ValueObservation.tracking { _ in V1() }, - ValueObservation.tracking { _ in V2() }, - ValueObservation.tracking { _ in V3() }, - ValueObservation.tracking { _ in V4() }, - ValueObservation.tracking { _ in V5() }) - var value: (V1, V2, V3, V4, V5)? - _ = try observation.start( - in: makeDatabaseQueue(), - scheduling: .immediate, // So that we can test the fresh value synchronously - onError: { error in XCTFail("Unexpected error: \(error)") }, - onChange: { value = $0 }) - XCTAssertNotNil(value) - } - - func testHeterogeneusCombine6() throws { - struct V1 { } - struct V2 { } - struct V3 { } - struct V4 { } - struct V5 { } - struct V6 { } - let observation = ValueObservation.combine( - ValueObservation.tracking { _ in V1() }, - ValueObservation.tracking { _ in V2() }, - ValueObservation.tracking { _ in V3() }, - ValueObservation.tracking { _ in V4() }, - ValueObservation.tracking { _ in V5() }, - ValueObservation.tracking { _ in V6() }) - var value: (V1, V2, V3, V4, V5, V6)? - _ = try observation.start( - in: makeDatabaseQueue(), - scheduling: .immediate, // So that we can test the fresh value synchronously - onError: { error in XCTFail("Unexpected error: \(error)") }, - onChange: { value = $0 }) - XCTAssertNotNil(value) - } - - func testHeterogeneusCombine7() throws { - struct V1 { } - struct V2 { } - struct V3 { } - struct V4 { } - struct V5 { } - struct V6 { } - struct V7 { } - let observation = ValueObservation.combine( - ValueObservation.tracking { _ in V1() }, - ValueObservation.tracking { _ in V2() }, - ValueObservation.tracking { _ in V3() }, - ValueObservation.tracking { _ in V4() }, - ValueObservation.tracking { _ in V5() }, - ValueObservation.tracking { _ in V6() }, - ValueObservation.tracking { _ in V7() }) - var value: (V1, V2, V3, V4, V5, V6, V7)? - _ = try observation.start( - in: makeDatabaseQueue(), - scheduling: .immediate, // So that we can test the fresh value synchronously - onError: { error in XCTFail("Unexpected error: \(error)") }, - onChange: { value = $0 }) - XCTAssertNotNil(value) - } - - func testHeterogeneusCombine8() throws { - struct V1 { } - struct V2 { } - struct V3 { } - struct V4 { } - struct V5 { } - struct V6 { } - struct V7 { } - struct V8 { } - let observation = ValueObservation.combine( - ValueObservation.tracking { _ in V1() }, - ValueObservation.tracking { _ in V2() }, - ValueObservation.tracking { _ in V3() }, - ValueObservation.tracking { _ in V4() }, - ValueObservation.tracking { _ in V5() }, - ValueObservation.tracking { _ in V6() }, - ValueObservation.tracking { _ in V7() }, - ValueObservation.tracking { _ in V8() }) - var value: (V1, V2, V3, V4, V5, V6, V7, V8)? - _ = try observation.start( - in: makeDatabaseQueue(), - scheduling: .immediate, // So that we can test the fresh value synchronously - onError: { error in XCTFail("Unexpected error: \(error)") }, - onChange: { value = $0 }) - XCTAssertNotNil(value) - } - - func testHeterogeneusCombined2() throws { - struct V1 { } - struct V2 { } - struct Combined { } - let observation1 = ValueObservation.tracking { _ in V1() } - let observation2 = ValueObservation.tracking { _ in V2() } - let observation = observation1.combine(observation2) { (v1: V1, v2: V2) -> Combined in Combined() } - var value: Combined? - _ = try observation.start( - in: makeDatabaseQueue(), - scheduling: .immediate, // So that we can test the fresh value synchronously - onError: { error in XCTFail("Unexpected error: \(error)") }, - onChange: { value = $0 }) - XCTAssertNotNil(value) - } - - func testHeterogeneusCombined3() throws { - struct V1 { } - struct V2 { } - struct V3 { } - struct Combined { } - let observation1 = ValueObservation.tracking { _ in V1() } - let observation2 = ValueObservation.tracking { _ in V2() } - let observation3 = ValueObservation.tracking { _ in V3() } - let observation = observation1.combine(observation2, observation3) { (v1: V1, v2: V2, v3: V3) -> Combined in Combined() } - var value: Combined? - _ = try observation.start( - in: makeDatabaseQueue(), - scheduling: .immediate, // So that we can test the fresh value synchronously - onError: { error in XCTFail("Unexpected error: \(error)") }, - onChange: { value = $0 }) - XCTAssertNotNil(value) - } - - func testHeterogeneusCombined4() throws { - struct V1 { } - struct V2 { } - struct V3 { } - struct V4 { } - struct Combined { } - let observation1 = ValueObservation.tracking { _ in V1() } - let observation2 = ValueObservation.tracking { _ in V2() } - let observation3 = ValueObservation.tracking { _ in V3() } - let observation4 = ValueObservation.tracking { _ in V4() } - let observation = observation1.combine(observation2, observation3, observation4) { (v1: V1, v2: V2, v3: V3, v4: V4) -> Combined in Combined() } - var value: Combined? - _ = try observation.start( - in: makeDatabaseQueue(), - scheduling: .immediate, // So that we can test the fresh value synchronously - onError: { error in XCTFail("Unexpected error: \(error)") }, - onChange: { value = $0 }) - XCTAssertNotNil(value) - } - - func testHeterogeneusCombined5() throws { - struct V1 { } - struct V2 { } - struct V3 { } - struct V4 { } - struct V5 { } - struct Combined { } - let observation1 = ValueObservation.tracking { _ in V1() } - let observation2 = ValueObservation.tracking { _ in V2() } - let observation3 = ValueObservation.tracking { _ in V3() } - let observation4 = ValueObservation.tracking { _ in V4() } - let observation5 = ValueObservation.tracking { _ in V5() } - let observation = observation1.combine(observation2, observation3, observation4, observation5) { (v1: V1, v2: V2, v3: V3, v4: V4, v5: V5) -> Combined in Combined() } - var value: Combined? - _ = try observation.start( - in: makeDatabaseQueue(), - scheduling: .immediate, // So that we can test the fresh value synchronously - onError: { error in XCTFail("Unexpected error: \(error)") }, - onChange: { value = $0 }) - XCTAssertNotNil(value) - } -}