diff --git a/GRDB.xcodeproj/project.pbxproj b/GRDB.xcodeproj/project.pbxproj index 80c2ebee0..cdb1b07cf 100755 --- a/GRDB.xcodeproj/project.pbxproj +++ b/GRDB.xcodeproj/project.pbxproj @@ -170,6 +170,9 @@ 563B8F93249E6171007A48C9 /* Trace.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563B8F91249E6171007A48C9 /* Trace.swift */; }; 563B8F94249E6171007A48C9 /* Trace.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563B8F91249E6171007A48C9 /* Trace.swift */; }; 563B8F95249E6171007A48C9 /* Trace.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563B8F91249E6171007A48C9 /* Trace.swift */; }; + 563B8FA1249E8ACB007A48C9 /* ValueObservationPrintTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563B8FA0249E8ACB007A48C9 /* ValueObservationPrintTests.swift */; }; + 563B8FA2249E8ACB007A48C9 /* ValueObservationPrintTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563B8FA0249E8ACB007A48C9 /* ValueObservationPrintTests.swift */; }; + 563B8FA3249E8ACB007A48C9 /* ValueObservationPrintTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563B8FA0249E8ACB007A48C9 /* ValueObservationPrintTests.swift */; }; 563C67B324628BEA00E94EDC /* DatabasePoolTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563C67B224628BEA00E94EDC /* DatabasePoolTests.swift */; }; 563C67B424628BEA00E94EDC /* DatabasePoolTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563C67B224628BEA00E94EDC /* DatabasePoolTests.swift */; }; 563C67B524628BEA00E94EDC /* DatabasePoolTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563C67B224628BEA00E94EDC /* DatabasePoolTests.swift */; }; @@ -1250,6 +1253,7 @@ 563B071421862C4600B38F35 /* ValueObservationRecordTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ValueObservationRecordTests.swift; sourceTree = ""; }; 563B071721862F4C00B38F35 /* ValueObservationDatabaseValueConvertibleTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ValueObservationDatabaseValueConvertibleTests.swift; sourceTree = ""; }; 563B8F91249E6171007A48C9 /* Trace.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Trace.swift; sourceTree = ""; }; + 563B8FA0249E8ACB007A48C9 /* ValueObservationPrintTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ValueObservationPrintTests.swift; sourceTree = ""; }; 563C67B224628BEA00E94EDC /* DatabasePoolTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabasePoolTests.swift; sourceTree = ""; }; 563DE4EC231A91E2005081B7 /* DatabaseConfigurationTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseConfigurationTests.swift; sourceTree = ""; }; 563EF414215F87EB007DAACD /* OrderedDictionary.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OrderedDictionary.swift; sourceTree = ""; }; @@ -1820,6 +1824,7 @@ 563B071721862F4C00B38F35 /* ValueObservationDatabaseValueConvertibleTests.swift */, 563B06C92185D2E500B38F35 /* ValueObservationFetchTests.swift */, 564CE4E821B2E06F00652B19 /* ValueObservationMapTests.swift */, + 563B8FA0249E8ACB007A48C9 /* ValueObservationPrintTests.swift */, 5656A7F822946B33001FF3FF /* ValueObservationQueryInterfaceRequestTests.swift */, 563B06C22185D29F00B38F35 /* ValueObservationReadonlyTests.swift */, 56677C0C241CD0D00050755D /* ValueObservationRecorder.swift */, @@ -3147,6 +3152,7 @@ 56915783231BF28B00E1D237 /* PoolTests.swift in Sources */, 56E8CE0E1BB4FA5600828BEC /* DatabaseValueConvertibleFetchTests.swift in Sources */, 5665FA342129EEA0004D8612 /* DatabaseDateEncodingStrategyTests.swift in Sources */, + 563B8FA2249E8ACB007A48C9 /* ValueObservationPrintTests.swift in Sources */, 56A238581B9C74A90082EB20 /* RecordPrimaryKeyRowIDTests.swift in Sources */, 56A5EF131EF7F20B00F03071 /* ForeignKeyInfoTests.swift in Sources */, 5653EAE920944B4F00F46237 /* AssociationChainSQLTests.swift in Sources */, @@ -3355,6 +3361,7 @@ 56915782231BF28B00E1D237 /* PoolTests.swift in Sources */, 56D4968E1D81316E008276D7 /* RowCopiedFromStatementTests.swift in Sources */, 5665FA332129EEA0004D8612 /* DatabaseDateEncodingStrategyTests.swift in Sources */, + 563B8FA1249E8ACB007A48C9 /* ValueObservationPrintTests.swift in Sources */, 56CC9246201E058100CB597E /* DropFirstCursorTests.swift in Sources */, 5698AC401DA2BED90056AF8C /* FTS3PatternTests.swift in Sources */, 562393571DEE013C00A6B01F /* FilterCursorTests.swift in Sources */, @@ -3694,6 +3701,7 @@ 56915784231BF28B00E1D237 /* PoolTests.swift in Sources */, AAA4DD88230F262000C74B15 /* DatabaseValueConvertibleFetchTests.swift in Sources */, AAA4DD89230F262000C74B15 /* DatabaseDateEncodingStrategyTests.swift in Sources */, + 563B8FA3249E8ACB007A48C9 /* ValueObservationPrintTests.swift in Sources */, AAA4DD8A230F262000C74B15 /* RecordPrimaryKeyRowIDTests.swift in Sources */, AAA4DD8B230F262000C74B15 /* ForeignKeyInfoTests.swift in Sources */, AAA4DD8C230F262000C74B15 /* AssociationChainSQLTests.swift in Sources */, diff --git a/GRDBCustom.xcodeproj/project.pbxproj b/GRDBCustom.xcodeproj/project.pbxproj index 7c90e2b5d..a8d566fed 100755 --- a/GRDBCustom.xcodeproj/project.pbxproj +++ b/GRDBCustom.xcodeproj/project.pbxproj @@ -89,6 +89,8 @@ 563B071C21862F5600B38F35 /* ValueObservationDatabaseValueConvertibleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563B071A21862F5600B38F35 /* ValueObservationDatabaseValueConvertibleTests.swift */; }; 563B8F9B249E74E5007A48C9 /* Trace.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563B8F99249E74E5007A48C9 /* Trace.swift */; }; 563B8F9C249E74E5007A48C9 /* Trace.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563B8F99249E74E5007A48C9 /* Trace.swift */; }; + 563B8F9E249E8AB0007A48C9 /* ValueObservationPrintTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563B8F9D249E8AB0007A48C9 /* ValueObservationPrintTests.swift */; }; + 563B8F9F249E8AB0007A48C9 /* ValueObservationPrintTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563B8F9D249E8AB0007A48C9 /* ValueObservationPrintTests.swift */; }; 563C67B824628C0C00E94EDC /* DatabasePoolTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563C67B624628C0C00E94EDC /* DatabasePoolTests.swift */; }; 563C67B924628C0C00E94EDC /* DatabasePoolTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563C67B624628C0C00E94EDC /* DatabasePoolTests.swift */; }; 563DE4F8231A91F6005081B7 /* DatabaseConfigurationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563DE4F6231A91F6005081B7 /* DatabaseConfigurationTests.swift */; }; @@ -785,6 +787,7 @@ 563B071121862C3E00B38F35 /* ValueObservationRecordTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ValueObservationRecordTests.swift; sourceTree = ""; }; 563B071A21862F5600B38F35 /* ValueObservationDatabaseValueConvertibleTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ValueObservationDatabaseValueConvertibleTests.swift; sourceTree = ""; }; 563B8F99249E74E5007A48C9 /* Trace.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Trace.swift; sourceTree = ""; }; + 563B8F9D249E8AB0007A48C9 /* ValueObservationPrintTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ValueObservationPrintTests.swift; sourceTree = ""; }; 563C67B624628C0C00E94EDC /* DatabasePoolTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabasePoolTests.swift; sourceTree = ""; }; 563DE4F6231A91F6005081B7 /* DatabaseConfigurationTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseConfigurationTests.swift; sourceTree = ""; }; 563EF41E215F8A76007DAACD /* OrderedDictionary.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OrderedDictionary.swift; sourceTree = ""; }; @@ -1326,6 +1329,7 @@ 563B071A21862F5600B38F35 /* ValueObservationDatabaseValueConvertibleTests.swift */, 563B06CE2185E04600B38F35 /* ValueObservationFetchTests.swift */, 564CE4E221B2E05400652B19 /* ValueObservationMapTests.swift */, + 563B8F9D249E8AB0007A48C9 /* ValueObservationPrintTests.swift */, 5656A7F422946B1B001FF3FF /* ValueObservationQueryInterfaceRequestTests.swift */, 563B06CD2185E04600B38F35 /* ValueObservationReadonlyTests.swift */, 56677C24241E6EA20050755D /* ValueObservationRecorder.swift */, @@ -2415,6 +2419,7 @@ 5698AC9D1DA4B0430056AF8C /* FTS4RecordTests.swift in Sources */, 5665FA3E2129EED8004D8612 /* DatabaseDateEncodingStrategyTests.swift in Sources */, 56677C28241E6EA20050755D /* ValueObservationRecorder.swift in Sources */, + 563B8F9F249E8AB0007A48C9 /* ValueObservationPrintTests.swift in Sources */, 5644DE8020F8D1D1001FFDDE /* DatabaseValueConversionErrorTests.swift in Sources */, 56A4CDB71D4234B200B1A9B9 /* SQLExpressionLiteralTests.swift in Sources */, 56CC924A201E058900CB597E /* DropFirstCursorTests.swift in Sources */, @@ -2754,6 +2759,7 @@ 5623935A1DEE013C00A6B01F /* FilterCursorTests.swift in Sources */, 5665FA3D2129EED8004D8612 /* DatabaseDateEncodingStrategyTests.swift in Sources */, 56677C27241E6EA20050755D /* ValueObservationRecorder.swift in Sources */, + 563B8F9E249E8AB0007A48C9 /* ValueObservationPrintTests.swift in Sources */, 5644DE7F20F8D1D1001FFDDE /* DatabaseValueConversionErrorTests.swift in Sources */, F3BA80FC1CFB3021003DC1BA /* UpdateStatementTests.swift in Sources */, 56CC9249201E058900CB597E /* DropFirstCursorTests.swift in Sources */, diff --git a/README.md b/README.md index 3dd6ee799..046d85353 100644 --- a/README.md +++ b/README.md @@ -5612,7 +5612,7 @@ The `print` operator logs messages for all ValueObservation events. ```swift let observation = ValueObservation - .tracking(Player.fetchAll) + .tracking { db in ... } .print() ``` diff --git a/Tests/CocoaPods/SQLCipher3/GRDBTests.xcodeproj/project.pbxproj b/Tests/CocoaPods/SQLCipher3/GRDBTests.xcodeproj/project.pbxproj index a39754704..35545ee0b 100644 --- a/Tests/CocoaPods/SQLCipher3/GRDBTests.xcodeproj/project.pbxproj +++ b/Tests/CocoaPods/SQLCipher3/GRDBTests.xcodeproj/project.pbxproj @@ -23,6 +23,8 @@ 561CFAAF2376EFBE000C8BAA /* AssociationHasManyThroughOrderingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 561CFAAC2376EFBD000C8BAA /* AssociationHasManyThroughOrderingTests.swift */; }; 561CFAB02376EFBE000C8BAA /* AssociationHasManyOrderingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 561CFAAD2376EFBE000C8BAA /* AssociationHasManyOrderingTests.swift */; }; 561CFAB12376EFBE000C8BAA /* AssociationHasManyOrderingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 561CFAAD2376EFBE000C8BAA /* AssociationHasManyOrderingTests.swift */; }; + 563B8FA8249E8B14007A48C9 /* ValueObservationPrintTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563B8FA7249E8B14007A48C9 /* ValueObservationPrintTests.swift */; }; + 563B8FA9249E8B14007A48C9 /* ValueObservationPrintTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563B8FA7249E8B14007A48C9 /* ValueObservationPrintTests.swift */; }; 563DE4FB231A9212005081B7 /* DatabaseConfigurationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563DE4FA231A9212005081B7 /* DatabaseConfigurationTests.swift */; }; 563DE4FC231A9212005081B7 /* DatabaseConfigurationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563DE4FA231A9212005081B7 /* DatabaseConfigurationTests.swift */; }; 564A1FDE226B89E1001F64F1 /* MutablePersistableRecordDeleteTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A1F27226B89CE001F64F1 /* MutablePersistableRecordDeleteTests.swift */; }; @@ -417,6 +419,7 @@ 561CFA8223735091000C8BAA /* MutablePersistableRecordUpdateTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MutablePersistableRecordUpdateTests.swift; sourceTree = ""; }; 561CFAAC2376EFBD000C8BAA /* AssociationHasManyThroughOrderingTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationHasManyThroughOrderingTests.swift; sourceTree = ""; }; 561CFAAD2376EFBE000C8BAA /* AssociationHasManyOrderingTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationHasManyOrderingTests.swift; sourceTree = ""; }; + 563B8FA7249E8B14007A48C9 /* ValueObservationPrintTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ValueObservationPrintTests.swift; sourceTree = ""; }; 563DE4FA231A9212005081B7 /* DatabaseConfigurationTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseConfigurationTests.swift; sourceTree = ""; }; 563F4CB9242F801A0052E96C /* ValueObservationRecordTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ValueObservationRecordTests.swift; sourceTree = ""; }; 564A1F1D226B876D001F64F1 /* GRDBTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = GRDBTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -661,6 +664,8 @@ 564A1F1F226B876D001F64F1 /* GRDBTests */ = { isa = PBXGroup; children = ( + 564A1F26226B89CD001F64F1 /* GRDBTests-Bridging-Header.h */, + 564A1F6F226B89D6001F64F1 /* Betty.jpeg */, 564A1F90226B89D9001F64F1 /* AnyCursorTests.swift */, 564A1F60226B89D4001F64F1 /* AssociationAggregateTests.swift */, 564A1F35226B89CF001F64F1 /* AssociationBelongsToDecodableRecordTests.swift */, @@ -693,7 +698,6 @@ 560714EF227DD1810091BB10 /* AssociationPrefetchingSQLTests.swift */, 564A1F3E226B89D0001F64F1 /* AssociationRowScopeSearchTests.swift */, 564A1FCF226B89E0001F64F1 /* AssociationTableAliasTestsSQLTests.swift */, - 564A1F6F226B89D6001F64F1 /* Betty.jpeg */, 564A1F8A226B89D9001F64F1 /* CGFloatTests.swift */, 564A1F61226B89D4001F64F1 /* ColumnExpressionTests.swift */, 564A1FAC226B89DC001F64F1 /* ColumnInfoTests.swift */, @@ -786,7 +790,6 @@ 564A1FC4226B89DE001F64F1 /* FTS5TokenizerTests.swift */, 564A1F43226B89D0001F64F1 /* FTS5WrapperTokenizerTests.swift */, 564A1FD5226B89E0001F64F1 /* GRDBTestCase.swift */, - 564A1F26226B89CD001F64F1 /* GRDBTests-Bridging-Header.h */, 564A1F86226B89D8001F64F1 /* IndexInfoTests.swift */, 564A1FCD226B89DF001F64F1 /* JoinSupportTests.swift */, 564A1FB8226B89DD001F64F1 /* MapCursorTests.swift */, @@ -851,6 +854,7 @@ 564A1F6C226B89D5001F64F1 /* ValueObservationDatabaseValueConvertibleTests.swift */, 564A1FC6226B89DF001F64F1 /* ValueObservationFetchTests.swift */, 564A1F59226B89D3001F64F1 /* ValueObservationMapTests.swift */, + 563B8FA7249E8B14007A48C9 /* ValueObservationPrintTests.swift */, 5656A801229474DC001FF3FF /* ValueObservationQueryInterfaceRequestTests.swift */, 564A1F85226B89D8001F64F1 /* ValueObservationReadonlyTests.swift */, 56C8123924279584004FBBFF /* ValueObservationRecorder.swift */, @@ -1227,6 +1231,7 @@ 564A208A226B89E1001F64F1 /* MutablePersistableRecordChangesTests.swift in Sources */, 564A2092226B89E1001F64F1 /* DatabasePoolConcurrencyTests.swift in Sources */, 564A1FE0226B89E1001F64F1 /* RowCopiedFromStatementTests.swift in Sources */, + 563B8FA8249E8B14007A48C9 /* ValueObservationPrintTests.swift in Sources */, 564A2007226B89E1001F64F1 /* FoundationDataTests.swift in Sources */, 564A201A226B89E1001F64F1 /* FTS4TableBuilderTests.swift in Sources */, 564A2059226B89E1001F64F1 /* DatabaseValueConversionTests.swift in Sources */, @@ -1430,6 +1435,7 @@ 564A2127226B8E18001F64F1 /* MutablePersistableRecordChangesTests.swift in Sources */, 564A2128226B8E18001F64F1 /* DatabasePoolConcurrencyTests.swift in Sources */, 564A2129226B8E18001F64F1 /* RowCopiedFromStatementTests.swift in Sources */, + 563B8FA9249E8B14007A48C9 /* ValueObservationPrintTests.swift in Sources */, 564A212A226B8E18001F64F1 /* FoundationDataTests.swift in Sources */, 564A212B226B8E18001F64F1 /* FTS4TableBuilderTests.swift in Sources */, 564A212C226B8E18001F64F1 /* DatabaseValueConversionTests.swift in Sources */, diff --git a/Tests/CocoaPods/SQLCipher4/GRDBTests.xcodeproj/project.pbxproj b/Tests/CocoaPods/SQLCipher4/GRDBTests.xcodeproj/project.pbxproj index 5074166e3..0fe5f02ad 100644 --- a/Tests/CocoaPods/SQLCipher4/GRDBTests.xcodeproj/project.pbxproj +++ b/Tests/CocoaPods/SQLCipher4/GRDBTests.xcodeproj/project.pbxproj @@ -23,6 +23,8 @@ 561CFAA92376EFAD000C8BAA /* AssociationHasManyThroughOrderingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 561CFAA62376EFAD000C8BAA /* AssociationHasManyThroughOrderingTests.swift */; }; 561CFAAA2376EFAD000C8BAA /* AssociationHasManyOrderingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 561CFAA72376EFAD000C8BAA /* AssociationHasManyOrderingTests.swift */; }; 561CFAAB2376EFAD000C8BAA /* AssociationHasManyOrderingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 561CFAA72376EFAD000C8BAA /* AssociationHasManyOrderingTests.swift */; }; + 563B8FA5249E8AF6007A48C9 /* ValueObservationPrintTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563B8FA4249E8AF6007A48C9 /* ValueObservationPrintTests.swift */; }; + 563B8FA6249E8AF6007A48C9 /* ValueObservationPrintTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563B8FA4249E8AF6007A48C9 /* ValueObservationPrintTests.swift */; }; 563DE4FE231A9239005081B7 /* DatabaseConfigurationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563DE4FD231A9238005081B7 /* DatabaseConfigurationTests.swift */; }; 563DE4FF231A9239005081B7 /* DatabaseConfigurationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563DE4FD231A9238005081B7 /* DatabaseConfigurationTests.swift */; }; 563F4CB7242F80030052E96C /* ValueObservationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563F4CB6242F80030052E96C /* ValueObservationTests.swift */; }; @@ -421,6 +423,7 @@ 561CFA7F2373507D000C8BAA /* MutablePersistableRecordUpdateTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MutablePersistableRecordUpdateTests.swift; sourceTree = ""; }; 561CFAA62376EFAD000C8BAA /* AssociationHasManyThroughOrderingTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationHasManyThroughOrderingTests.swift; sourceTree = ""; }; 561CFAA72376EFAD000C8BAA /* AssociationHasManyOrderingTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationHasManyOrderingTests.swift; sourceTree = ""; }; + 563B8FA4249E8AF6007A48C9 /* ValueObservationPrintTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ValueObservationPrintTests.swift; sourceTree = ""; }; 563DE4FD231A9238005081B7 /* DatabaseConfigurationTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseConfigurationTests.swift; sourceTree = ""; }; 563F4CB6242F80030052E96C /* ValueObservationTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ValueObservationTests.swift; sourceTree = ""; }; 564A1F1D226B876D001F64F1 /* GRDBTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = GRDBTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -666,6 +669,9 @@ 564A1F1F226B876D001F64F1 /* GRDBTests */ = { isa = PBXGroup; children = ( + 564A1F26226B89CD001F64F1 /* GRDBTests-Bridging-Header.h */, + 564A1F6F226B89D6001F64F1 /* Betty.jpeg */, + 564A2158226C8F24001F64F1 /* db.SQLCipher3 */, 564A1F90226B89D9001F64F1 /* AnyCursorTests.swift */, 564A1F60226B89D4001F64F1 /* AssociationAggregateTests.swift */, 564A1F35226B89CF001F64F1 /* AssociationBelongsToDecodableRecordTests.swift */, @@ -698,7 +704,6 @@ 560714F2227DD1AD0091BB10 /* AssociationPrefetchingSQLTests.swift */, 564A1F3E226B89D0001F64F1 /* AssociationRowScopeSearchTests.swift */, 564A1FCF226B89E0001F64F1 /* AssociationTableAliasTestsSQLTests.swift */, - 564A1F6F226B89D6001F64F1 /* Betty.jpeg */, 564A1F8A226B89D9001F64F1 /* CGFloatTests.swift */, 564A1F61226B89D4001F64F1 /* ColumnExpressionTests.swift */, 564A1FAC226B89DC001F64F1 /* ColumnInfoTests.swift */, @@ -751,7 +756,6 @@ 564A1F45226B89D0001F64F1 /* DatabaseValueTests.swift */, 564A1FC0226B89DE001F64F1 /* DatabaseWriterTests.swift */, 564A1FCC226B89DF001F64F1 /* DataMemoryTests.swift */, - 564A2158226C8F24001F64F1 /* db.SQLCipher3 */, 564A1F4B226B89D1001F64F1 /* DerivableRequestTests.swift */, 564A1FBB226B89DD001F64F1 /* DropFirstCursorTests.swift */, 564A1F6D226B89D5001F64F1 /* DropWhileCursorTests.swift */, @@ -792,7 +796,6 @@ 564A1FC4226B89DE001F64F1 /* FTS5TokenizerTests.swift */, 564A1F43226B89D0001F64F1 /* FTS5WrapperTokenizerTests.swift */, 564A1FD5226B89E0001F64F1 /* GRDBTestCase.swift */, - 564A1F26226B89CD001F64F1 /* GRDBTests-Bridging-Header.h */, 564A1F86226B89D8001F64F1 /* IndexInfoTests.swift */, 564A1FCD226B89DF001F64F1 /* JoinSupportTests.swift */, 564A1FB8226B89DD001F64F1 /* MapCursorTests.swift */, @@ -857,6 +860,7 @@ 564A1F6C226B89D5001F64F1 /* ValueObservationDatabaseValueConvertibleTests.swift */, 564A1FC6226B89DF001F64F1 /* ValueObservationFetchTests.swift */, 564A1F59226B89D3001F64F1 /* ValueObservationMapTests.swift */, + 563B8FA4249E8AF6007A48C9 /* ValueObservationPrintTests.swift */, 5656A804229474F4001FF3FF /* ValueObservationQueryInterfaceRequestTests.swift */, 564A1F85226B89D8001F64F1 /* ValueObservationReadonlyTests.swift */, 56C8122F24279549004FBBFF /* ValueObservationRecorder.swift */, @@ -1092,6 +1096,7 @@ 564A2049226B89E1001F64F1 /* DatabaseQueueReadOnlyTests.swift in Sources */, 564A1FF0226B89E1001F64F1 /* AssociationHasOneThroughDecodableRecordTests.swift in Sources */, 564A1FEA226B89E1001F64F1 /* AssociationChainRowScopesTests.swift in Sources */, + 563B8FA5249E8AF6007A48C9 /* ValueObservationPrintTests.swift in Sources */, 564A207D226B89E1001F64F1 /* ValueObservationFetchTests.swift in Sources */, 564A203C226B89E1001F64F1 /* ValueObservationReadonlyTests.swift in Sources */, 564A203B226B89E1001F64F1 /* ValueObservationCountTests.swift in Sources */, @@ -1296,6 +1301,7 @@ 564A20A4226B8E18001F64F1 /* DatabaseQueueReadOnlyTests.swift in Sources */, 564A20A5226B8E18001F64F1 /* AssociationHasOneThroughDecodableRecordTests.swift in Sources */, 564A20A6226B8E18001F64F1 /* AssociationChainRowScopesTests.swift in Sources */, + 563B8FA6249E8AF6007A48C9 /* ValueObservationPrintTests.swift in Sources */, 564A20A8226B8E18001F64F1 /* ValueObservationFetchTests.swift in Sources */, 564A20A9226B8E18001F64F1 /* ValueObservationReadonlyTests.swift in Sources */, 564A20AA226B8E18001F64F1 /* ValueObservationCountTests.swift in Sources */, diff --git a/Tests/GRDBTests/ValueObservationPrintTests.swift b/Tests/GRDBTests/ValueObservationPrintTests.swift new file mode 100644 index 000000000..9b4f323d0 --- /dev/null +++ b/Tests/GRDBTests/ValueObservationPrintTests.swift @@ -0,0 +1,516 @@ +import XCTest +import Dispatch +@testable import GRDB + +class ValueObservationPrintTests: GRDBTestCase { + class TestStream: TextOutputStream { + @LockedBox var strings: [String] = [] + func write(_ string: String) { + strings.append(string) + } + } + + // MARK: - Readonly + + func test_readonly_success_asynchronousScheduling() throws { + let dbPool = try makeDatabasePool(filename: "test") + try dbPool.write { db in + try db.execute(sql: "CREATE TABLE player(id INTEGER PRIMARY KEY)") + } + + func test(_ dbReader: DatabaseReader) throws { + let logger = TestStream() + let observation = ValueObservation + .tracking { try Int.fetchOne($0, sql: "SELECT COUNT(*) FROM player")! } + .print(to: logger) + + let expectation = self.expectation(description: "") + let cancellable = observation.start( + in: dbReader, + scheduling: .async(onQueue: .main), + onError: { _ in }, + onChange: { _ in expectation.fulfill() }) + withExtendedLifetime(cancellable) { + waitForExpectations(timeout: 1, handler: nil) + XCTAssertEqual(logger.strings, [ + "start", + "fetch", + "value: 0"]) + } + } + + var config = dbConfiguration! + config.readonly = true + try test(makeDatabaseQueue(filename: "test", configuration: config)) + try test(makeDatabasePool(filename: "test", configuration: config)) + try test(makeDatabasePool(filename: "test", configuration: config).makeSnapshot()) + } + + func test_readonly_success_immediateScheduling() throws { + let dbPool = try makeDatabasePool(filename: "test") + try dbPool.write { db in + try db.execute(sql: "CREATE TABLE player(id INTEGER PRIMARY KEY)") + } + + func test(_ dbReader: DatabaseReader) throws { + let logger = TestStream() + let observation = ValueObservation + .tracking { try Int.fetchOne($0, sql: "SELECT COUNT(*) FROM player")! } + .print(to: logger) + + let expectation = self.expectation(description: "") + let cancellable = observation.start( + in: dbReader, + scheduling: .immediate, + onError: { _ in }, + onChange: { _ in expectation.fulfill() }) + withExtendedLifetime(cancellable) { + waitForExpectations(timeout: 1, handler: nil) + XCTAssertEqual(logger.strings, [ + "start", + "fetch", + "value: 0"]) + } + } + + var config = dbConfiguration! + config.readonly = true + try test(makeDatabaseQueue(filename: "test", configuration: config)) + try test(makeDatabasePool(filename: "test", configuration: config)) + try test(makeDatabasePool(filename: "test", configuration: config).makeSnapshot()) + } + + func test_readonly_failure_asynchronousScheduling() throws { + _ = try makeDatabasePool(filename: "test") + + func test(_ dbReader: DatabaseReader) throws { + struct TestError: Error { } + let logger = TestStream() + let observation = ValueObservation + .tracking { _ in throw TestError() } + .print(to: logger) + + let expectation = self.expectation(description: "") + let cancellable = observation.start( + in: dbReader, + scheduling: .async(onQueue: .main), + onError: { _ in expectation.fulfill() }, + onChange: { _ in }) + withExtendedLifetime(cancellable) { + waitForExpectations(timeout: 1, handler: nil) + XCTAssertEqual(logger.strings, [ + "start", + "fetch", + "error: TestError()"]) + } + } + + var config = dbConfiguration! + config.readonly = true + try test(makeDatabaseQueue(filename: "test", configuration: config)) + try test(makeDatabasePool(filename: "test", configuration: config)) + try test(makeDatabasePool(filename: "test", configuration: config).makeSnapshot()) + } + + func test_readonly_failure_immediateScheduling() throws { + _ = try makeDatabasePool(filename: "test") + + func test(_ dbReader: DatabaseReader) throws { + struct TestError: Error { } + let logger = TestStream() + let observation = ValueObservation + .tracking { _ in throw TestError() } + .print(to: logger) + + let expectation = self.expectation(description: "") + let cancellable = observation.start( + in: dbReader, + scheduling: .immediate, + onError: { _ in expectation.fulfill() }, + onChange: { _ in }) + withExtendedLifetime(cancellable) { + waitForExpectations(timeout: 1, handler: nil) + XCTAssertEqual(logger.strings, [ + "start", + "fetch", + "error: TestError()"]) + } + } + + var config = dbConfiguration! + config.readonly = true + try test(makeDatabaseQueue(filename: "test", configuration: config)) + try test(makeDatabasePool(filename: "test", configuration: config)) + try test(makeDatabasePool(filename: "test", configuration: config).makeSnapshot()) + } + + // MARK: - Writeonly + + func test_writeonly_success_asynchronousScheduling() throws { + func test(_ dbWriter: DatabaseWriter) throws { + try dbWriter.write { db in + try db.execute(sql: "CREATE TABLE player(id INTEGER PRIMARY KEY)") + } + + let logger = TestStream() + var observation = ValueObservation + .tracking { try Int.fetchOne($0, sql: "SELECT COUNT(*) FROM player")! } + .print(to: logger) + observation.requiresWriteAccess = true + + let expectation = self.expectation(description: "") + expectation.expectedFulfillmentCount = 2 + let cancellable = observation.start( + in: dbWriter, + scheduling: .async(onQueue: .main), + onError: { _ in }, + onChange: { _ in + try! dbWriter.write { db in + try db.execute(sql: "INSERT INTO player DEFAULT VALUES") + } + expectation.fulfill() + }) + withExtendedLifetime(cancellable) { + waitForExpectations(timeout: 1, handler: nil) + XCTAssertEqual(logger.strings.prefix(7), [ + "start", + "fetch", + "tracked region: player(*)", + "value: 0", + "database did change", + "fetch", + "value: 1"]) + } + } + + try test(makeDatabaseQueue()) + try test(makeDatabasePool()) + } + + func test_writeonly_success_immediateScheduling() throws { + func test(_ dbWriter: DatabaseWriter) throws { + try dbWriter.write { db in + try db.execute(sql: "CREATE TABLE player(id INTEGER PRIMARY KEY)") + } + + let logger = TestStream() + var observation = ValueObservation + .tracking { try Int.fetchOne($0, sql: "SELECT COUNT(*) FROM player")! } + .print(to: logger) + observation.requiresWriteAccess = true + + let expectation = self.expectation(description: "") + expectation.expectedFulfillmentCount = 2 + let cancellable = observation.start( + in: dbWriter, + scheduling: .immediate, + onError: { _ in }, + onChange: { _ in + try! dbWriter.write { db in + try db.execute(sql: "INSERT INTO player DEFAULT VALUES") + } + expectation.fulfill() + }) + withExtendedLifetime(cancellable) { + waitForExpectations(timeout: 1, handler: nil) + XCTAssertEqual(logger.strings.prefix(7), [ + "start", + "fetch", + "tracked region: player(*)", + "value: 0", + "database did change", + "fetch", + "value: 1"]) + } + } + + try test(makeDatabaseQueue()) + try test(makeDatabasePool()) + } + + func test_writeonlyLate_immediateFailure_asynchronousScheduling() throws { + func test(_ dbWriter: DatabaseWriter) throws { + let logger = TestStream() + var observation = ValueObservation + .tracking { try Int.fetchOne($0, sql: "SELECT COUNT(*) FROM player")! } + .print(to: logger) + observation.requiresWriteAccess = true + + let expectation = self.expectation(description: "") + let cancellable = observation.start( + in: dbWriter, + scheduling: .async(onQueue: .main), + onError: { _ in expectation.fulfill() }, + onChange: { _ in }) + withExtendedLifetime(cancellable) { + waitForExpectations(timeout: 1, handler: nil) + XCTAssertEqual(logger.strings, [ + "start", + "fetch", + "error: SQLite error 1 with statement `SELECT COUNT(*) FROM player`: no such table: player"]) + } + } + + try test(makeDatabaseQueue()) + try test(makeDatabasePool()) + } + + func test_writeonlyLate_immediateFailure_immediateScheduling() throws { + func test(_ dbWriter: DatabaseWriter) throws { + let logger = TestStream() + var observation = ValueObservation + .tracking { try Int.fetchOne($0, sql: "SELECT COUNT(*) FROM player")! } + .print(to: logger) + observation.requiresWriteAccess = true + + let expectation = self.expectation(description: "") + let cancellable = observation.start( + in: dbWriter, + scheduling: .immediate, + onError: { _ in expectation.fulfill() }, + onChange: { _ in }) + withExtendedLifetime(cancellable) { + waitForExpectations(timeout: 1, handler: nil) + XCTAssertEqual(logger.strings, [ + "start", + "fetch", + "error: SQLite error 1 with statement `SELECT COUNT(*) FROM player`: no such table: player"]) + } + } + + try test(makeDatabaseQueue()) + try test(makeDatabasePool()) + } + + func test_writeonlyLate_lateFailure_asynchronousScheduling() throws { + func test(_ dbWriter: DatabaseWriter) throws { + try dbWriter.write { db in + try db.execute(sql: "CREATE TABLE player(id INTEGER PRIMARY KEY)") + } + + let logger = TestStream() + var observation = ValueObservation + .tracking { try Int.fetchOne($0, sql: "SELECT COUNT(*) FROM player")! } + .print(to: logger) + observation.requiresWriteAccess = true + + let expectation = self.expectation(description: "") + let cancellable = observation.start( + in: dbWriter, + scheduling: .async(onQueue: .main), + onError: { _ in expectation.fulfill() }, + onChange: { _ in + try! dbWriter.write { db in + try db.execute(sql: """ + INSERT INTO player DEFAULT VALUES; + DROP TABLE player; + """) + } + }) + withExtendedLifetime(cancellable) { + waitForExpectations(timeout: 1, handler: nil) + XCTAssertEqual(logger.strings, [ + "start", + "fetch", + "tracked region: player(*)", + "value: 0", + "database did change", + "fetch", + "error: SQLite error 1 with statement `SELECT COUNT(*) FROM player`: no such table: player"]) + } + } + + try test(makeDatabaseQueue()) + try test(makeDatabasePool()) + } + + func test_writeonlyLate_lateFailure_immediateScheduling() throws { + func test(_ dbWriter: DatabaseWriter) throws { + try dbWriter.write { db in + try db.execute(sql: "CREATE TABLE player(id INTEGER PRIMARY KEY)") + } + + let logger = TestStream() + var observation = ValueObservation + .tracking { try Int.fetchOne($0, sql: "SELECT COUNT(*) FROM player")! } + .print(to: logger) + observation.requiresWriteAccess = true + + let expectation = self.expectation(description: "") + let cancellable = observation.start( + in: dbWriter, + scheduling: .immediate, + onError: { _ in expectation.fulfill() }, + onChange: { _ in + try! dbWriter.write { db in + try db.execute(sql: """ + INSERT INTO player DEFAULT VALUES; + DROP TABLE player; + """) + } + }) + withExtendedLifetime(cancellable) { + waitForExpectations(timeout: 1, handler: nil) + XCTAssertEqual(logger.strings, [ + "start", + "fetch", + "tracked region: player(*)", + "value: 0", + "database did change", + "fetch", + "error: SQLite error 1 with statement `SELECT COUNT(*) FROM player`: no such table: player"]) + } + } + + try test(makeDatabaseQueue()) + try test(makeDatabasePool()) + } + + // MARK: - Concurrent + + func test_concurrent_success_asynchronousScheduling() throws { + let dbPool = try makeDatabasePool() + try dbPool.write { db in + try db.execute(sql: "CREATE TABLE player(id INTEGER PRIMARY KEY)") + } + + let logger = TestStream() + // Force DatabasePool to perform two initial fetches, because between + // its first read access, and its write access that installs the + // transaction observer, some write did happen. + var needsChange = true + let observation = ValueObservation + .tracking({ db -> Int in + if needsChange { + needsChange = false + try dbPool.write { db in + try db.execute(sql: """ + INSERT INTO player DEFAULT VALUES; + DELETE FROM player; + """) + } + } + return try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM player")! + }) + .print(to: logger) + + let expectation = self.expectation(description: "") + expectation.expectedFulfillmentCount = 2 + let cancellable = observation.start( + in: dbPool, + scheduling: .async(onQueue: .main), + onError: { _ in }, + onChange: { _ in expectation.fulfill() }) + withExtendedLifetime(cancellable) { + waitForExpectations(timeout: 1, handler: nil) + XCTAssertEqual(logger.strings, [ + "start", + "fetch", + "tracked region: player(*)", + "value: 0", + "database did change", + "fetch", + "value: 0"]) + } + } + + func test_concurrent_success_immediateScheduling() throws { + let dbPool = try makeDatabasePool() + try dbPool.write { db in + try db.execute(sql: "CREATE TABLE player(id INTEGER PRIMARY KEY)") + } + + let logger = TestStream() + // Force DatabasePool to perform two initial fetches, because between + // its first read access, and its write access that installs the + // transaction observer, some write did happen. + var needsChange = true + let observation = ValueObservation + .tracking({ db -> Int in + if needsChange { + needsChange = false + try dbPool.write { db in + try db.execute(sql: """ + INSERT INTO player DEFAULT VALUES; + DELETE FROM player; + """) + } + } + return try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM player")! + }) + .print(to: logger) + + let expectation = self.expectation(description: "") + expectation.expectedFulfillmentCount = 2 + let cancellable = observation.start( + in: dbPool, + scheduling: .immediate, + onError: { _ in }, + onChange: { _ in expectation.fulfill() }) + withExtendedLifetime(cancellable) { + waitForExpectations(timeout: 1, handler: nil) + XCTAssertEqual(logger.strings, [ + "start", + "fetch", + "tracked region: player(*)", + "value: 0", + "database did change", + "fetch", + "value: 0"]) + } + } + + // MARK: - Varying Database Region + + func test_varyingRegion() throws { + let dbQueue = try makeDatabaseQueue() + try dbQueue.write { db in + try db.execute(sql: """ + CREATE TABLE a(id INTEGER PRIMARY KEY); + CREATE TABLE b(id INTEGER PRIMARY KEY); + CREATE TABLE choice(t TEXT); + INSERT INTO choice (t) VALUES ('a'); + """) + } + + let logger = TestStream() + let observation = ValueObservation + .trackingVaryingRegion({ db -> Int in + let table = try String.fetchOne(db, sql: "SELECT t FROM choice")! + return try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM \(table)")! + }) + .print(to: logger) + + let expectation = self.expectation(description: "") + expectation.expectedFulfillmentCount = 3 + let cancellable = observation.start( + in: dbQueue, + scheduling: .async(onQueue: .main), + onError: { _ in }, + onChange: { _ in + try! dbQueue.write { db in + try db.execute(sql: """ + UPDATE choice SET t = 'b'; + INSERT INTO a DEFAULT VALUES; + INSERT INTO b DEFAULT VALUES; + """) + } + expectation.fulfill() + }) + withExtendedLifetime(cancellable) { + waitForExpectations(timeout: 1, handler: nil) + XCTAssertEqual(logger.strings.prefix(11), [ + "start", + "fetch", + "tracked region: a(*),choice(t)", + "value: 0", + "database did change", + "fetch", + "tracked region: b(*),choice(t)", + "value: 1", + "database did change", + "fetch", + "value: 2"]) + } + } +}