From 5dd86d2453f376c8f6742226f4386a81e6406d33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sun, 8 Mar 2020 17:53:39 +0100 Subject: [PATCH] Remove deprecated ValueObservation methods --- GRDB/Fixit/GRDB-5.0.swift | 62 +++++++ .../ValueObservation+Count.swift | 35 ---- ...Observation+DatabaseValueConvertible.swift | 116 ------------ .../ValueObservation+FetchableRecord.swift | 80 --------- .../ValueObservation+Row.swift | 75 -------- .../ValueReducer/CompactMap.swift | 4 - .../ValueObservation/ValueReducer/Fetch.swift | 4 - GRDB/ValueObservation/ValueReducer/Map.swift | 4 - .../ValueReducer/RemoveDuplicates.swift | 21 --- .../ValueObservationCountTests.swift | 34 ---- ...rvationDatabaseValueConvertibleTests.swift | 116 ------------ .../ValueObservationFetchTests.swift | 32 ---- ...bservationQueryInterfaceRequestTests.swift | 165 +----------------- .../ValueObservationRecordTests.swift | 74 +------- .../GRDBTests/ValueObservationRowTests.swift | 72 -------- 15 files changed, 64 insertions(+), 830 deletions(-) diff --git a/GRDB/Fixit/GRDB-5.0.swift b/GRDB/Fixit/GRDB-5.0.swift index 20372ac37..70a69aab6 100644 --- a/GRDB/Fixit/GRDB-5.0.swift +++ b/GRDB/Fixit/GRDB-5.0.swift @@ -88,6 +88,68 @@ extension Statement { { preconditionFailure() } } +extension ValueObservation where Reducer == Void { + @available(*, unavailable, message: "Use request.observationForCount() instead") + public static func trackingCount(_ request: Request) + -> ValueObservation>> + { preconditionFailure() } + + @available(*, unavailable, message: "Use request.observationForAll() instead") + public static func trackingAll(_ request: Request) + -> ValueObservation> + where Request.RowDecoder: DatabaseValueConvertible + { preconditionFailure() } + + @available(*, unavailable, message: "Use request.observationForFirst() instead") + public static func trackingOne(_ request: Request) + -> ValueObservation> + where Request.RowDecoder: DatabaseValueConvertible + { preconditionFailure() } + + @available(*, unavailable, message: "Use request.observationForAll() instead") + public static func trackingAll(_ request: Request) + -> ValueObservation> + where Request.RowDecoder: _OptionalProtocol, + Request.RowDecoder._Wrapped: DatabaseValueConvertible + { preconditionFailure() } + + @available(*, unavailable, message: "Use request.observationForAll() instead") + public static func trackingAll(_ request: Request) + -> ValueObservation> + where Request.RowDecoder: FetchableRecord + { preconditionFailure() } + + @available(*, unavailable, message: "Use request.observationForFirst() instead") + public static func trackingOne(_ request: Request) -> + ValueObservation> + where Request.RowDecoder: FetchableRecord + { preconditionFailure() } + + @available(*, unavailable, message: "Use request.observationForAll() instead") + public static func trackingAll(_ request: Request) + -> ValueObservation + where Request.RowDecoder == Row + { preconditionFailure() } + + @available(*, unavailable, message: "Use request.observationForFirst() instead") + public static func trackingOne(_ request: Request) + -> ValueObservation + where Request.RowDecoder == Row + { preconditionFailure() } +} + +extension ValueObservation where Reducer: ValueReducer, Reducer.Value: Equatable { + @available(*, unavailable, renamed: "removeDuplicates") + public func distinctUntilChanged() -> ValueObservation> + { preconditionFailure() } +} + +extension ValueReducer where Value: Equatable { + @available(*, unavailable, renamed: "removeDuplicates") + public func distinctUntilChanged() -> ValueReducers.RemoveDuplicates + { preconditionFailure() } +} + #if SQLITE_HAS_CODEC extension Configuration { @available(*, unavailable, message: "Use Database.usePassphrase(_:) in Configuration.prepareDatabase instead.") diff --git a/GRDB/ValueObservation/ValueObservation+Count.swift b/GRDB/ValueObservation/ValueObservation+Count.swift index a53c64089..05ef992f6 100644 --- a/GRDB/ValueObservation/ValueObservation+Count.swift +++ b/GRDB/ValueObservation/ValueObservation+Count.swift @@ -64,38 +64,3 @@ extension TableRecord { return all().observationForCount() } } - -extension ValueObservation where Reducer == Void { - - // MARK: - Count Observation - - /// Creates a ValueObservation which observes *request*, and notifies its - /// count whenever it is modified by a database transaction. - /// - /// For example: - /// - /// let request = Player.all() - /// let observation = ValueObservation.trackingCount(request) - /// - /// let observer = try observation.start(in: dbQueue) { count: Int in - /// print("Number of players has changed") - /// } - /// - /// The returned observation has the default configuration: - /// - /// - When started with the `start(in:onError:onChange:)` method, a fresh - /// value is immediately notified on the main queue. - /// - Upon subsequent database changes, fresh values are notified on the - /// main queue. - /// - The observation lasts until the observer returned by - /// `start` is deallocated. - /// - /// - parameter request: the observed request. - /// - returns: a ValueObservation. - @available(*, deprecated, message: "Use request.observationForCount() instead") - public static func trackingCount(_ request: Request) - -> ValueObservation>> - { - return request.observationForCount() - } -} diff --git a/GRDB/ValueObservation/ValueObservation+DatabaseValueConvertible.swift b/GRDB/ValueObservation/ValueObservation+DatabaseValueConvertible.swift index 298832ba5..5946ef3b4 100644 --- a/GRDB/ValueObservation/ValueObservation+DatabaseValueConvertible.swift +++ b/GRDB/ValueObservation/ValueObservation+DatabaseValueConvertible.swift @@ -124,107 +124,6 @@ extension FetchRequest where RowDecoder: _OptionalProtocol, RowDecoder._Wrapped: } } -extension ValueObservation where Reducer == Void { - - // MARK: - DatabaseValueConvertible Observation - - /// Creates a ValueObservation which observes *request*, and notifies - /// fresh values whenever the request is modified by a - /// database transaction. - /// - /// For example: - /// - /// let request = Player.select(Column("name"), as: String.self) - /// let observation = ValueObservation.trackingAll(request) - /// - /// let observer = try observation.start(in: dbQueue) { names: [String] in - /// print("Player names have changed") - /// } - /// - /// The returned observation has the default configuration: - /// - /// - When started with the `start(in:onError:onChange:)` method, a fresh - /// value is immediately notified on the main queue. - /// - Upon subsequent database changes, fresh values are notified on the - /// main queue. - /// - The observation lasts until the observer returned by - /// `start` is deallocated. - /// - /// - parameter request: the observed request. - /// - returns: a ValueObservation. - @available(*, deprecated, message: "Use request.observationForAll() instead") - public static func trackingAll(_ request: Request) - -> ValueObservation> - where Request.RowDecoder: DatabaseValueConvertible - { - return request.observationForAll() - } - - /// Creates a ValueObservation which observes *request*, and notifies a - /// fresh value whenever the request is modified by a database transaction. - /// - /// For example: - /// - /// let request = Player.select(max(Column("score")), as: Int.self) - /// let observation = ValueObservation.trackingOne(request) - /// - /// let observer = try observation.start(in: dbQueue) { maxScore: Int? in - /// print("Maximum score has changed") - /// } - /// - /// The returned observation has the default configuration: - /// - /// - When started with the `start(in:onError:onChange:)` method, a fresh - /// value is immediately notified on the main queue. - /// - Upon subsequent database changes, fresh values are notified on the - /// main queue. - /// - The observation lasts until the observer returned by - /// `start` is deallocated. - /// - /// - parameter request: the observed request. - /// - returns: a ValueObservation. - @available(*, deprecated, message: "Use request.observationForFirst() instead") - public static func trackingOne(_ request: Request) - -> ValueObservation> - where Request.RowDecoder: DatabaseValueConvertible - { - return request.observationForFirst() - } - - /// Creates a ValueObservation which observes *request*, and notifies - /// fresh values whenever the request is modified by a - /// database transaction. - /// - /// For example: - /// - /// let request = Player.select(Column("name"), as: Optional.self) - /// let observation = ValueObservation.trackingAll(request) - /// - /// let observer = try observation.start(in: dbQueue) { names: [String?] in - /// print("Player names have changed") - /// } - /// - /// The returned observation has the default configuration: - /// - /// - When started with the `start(in:onError:onChange:)` method, a fresh - /// value is immediately notified on the main queue. - /// - Upon subsequent database changes, fresh values are notified on the - /// main queue. - /// - The observation lasts until the observer returned by - /// `start` is deallocated. - /// - /// - parameter request: the observed request. - /// - returns: a ValueObservation. - @available(*, deprecated, message: "Use request.observationForAll() instead") - public static func trackingAll(_ request: Request) - -> ValueObservation> - where Request.RowDecoder: _OptionalProtocol, - Request.RowDecoder._Wrapped: DatabaseValueConvertible - { - return request.observationForAll() - } -} - extension ValueReducers { /// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features) /// @@ -332,18 +231,3 @@ extension ValueReducers { } } } - -/// :nodoc: -@available(*, deprecated, renamed: "ValueReducers.AllValues") -public typealias DatabaseValuesReducer = ValueReducers.AllValues - where RowDecoder: DatabaseValueConvertible - -/// :nodoc: -@available(*, deprecated, renamed: "ValueReducers.OneValue") -public typealias DatabaseValueReducer = ValueReducers.OneValue - where RowDecoder: DatabaseValueConvertible - -/// :nodoc: -@available(*, deprecated, renamed: "ValueReducers.AllOptionalValues") -public typealias OptionalDatabaseValuesReducer = ValueReducers.AllOptionalValues - where RowDecoder: DatabaseValueConvertible diff --git a/GRDB/ValueObservation/ValueObservation+FetchableRecord.swift b/GRDB/ValueObservation/ValueObservation+FetchableRecord.swift index f54b4cae5..75c82eea5 100644 --- a/GRDB/ValueObservation/ValueObservation+FetchableRecord.swift +++ b/GRDB/ValueObservation/ValueObservation+FetchableRecord.swift @@ -118,74 +118,6 @@ extension TableRecord where Self: FetchableRecord { } } -extension ValueObservation where Reducer == Void { - - // MARK: - FetchableRecord Observation - - /// Creates a ValueObservation which observes *request*, and notifies - /// fresh records whenever the request is modified by a - /// database transaction. - /// - /// For example: - /// - /// let request = Player.all() - /// let observation = ValueObservation.trackingAll(request) - /// - /// let observer = try observation.start(in: dbQueue) { players: [Player] in - /// print("Players have changed") - /// } - /// - /// The returned observation has the default configuration: - /// - /// - When started with the `start(in:onError:onChange:)` method, a fresh - /// value is immediately notified on the main queue. - /// - Upon subsequent database changes, fresh values are notified on the - /// main queue. - /// - The observation lasts until the observer returned by - /// `start` is deallocated. - /// - /// - parameter request: the observed request. - /// - returns: a ValueObservation. - @available(*, deprecated, message: "Use request.observationForAll() instead") - public static func trackingAll(_ request: Request) - -> ValueObservation> - where Request.RowDecoder: FetchableRecord - { - return request.observationForAll() - } - - /// Creates a ValueObservation which observes *request*, and notifies a - /// fresh record whenever the request is modified by a database transaction. - /// - /// For example: - /// - /// let request = Player.filter(key: 1) - /// let observation = ValueObservation.trackingOne(request) - /// - /// let observer = try observation.start(in: dbQueue) { player: Player? in - /// print("Player has changed") - /// } - /// - /// The returned observation has the default configuration: - /// - /// - When started with the `start(in:onError:onChange:)` method, a fresh - /// value is immediately notified on the main queue. - /// - Upon subsequent database changes, fresh values are notified on the - /// main queue. - /// - The observation lasts until the observer returned by - /// `start` is deallocated. - /// - /// - parameter request: the observed request. - /// - returns: a ValueObservation. - @available(*, deprecated, message: "Use request.observationForFirst() instead") - public static func trackingOne(_ request: Request) -> - ValueObservation> - where Request.RowDecoder: FetchableRecord - { - return request.observationForFirst() - } -} - extension ValueReducers { /// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features) /// @@ -247,15 +179,3 @@ extension ValueReducers { } } } - -/// :nodoc: -@available(*, deprecated, renamed: "ValueReducers.AllRecords") -public typealias FetchableRecordsReducer - = ValueReducers.AllRecords - where RowDecoder: FetchableRecord - -/// :nodoc: -@available(*, deprecated, renamed: "ValueReducers.OneRecord") -public typealias FetchableRecordReducer - = ValueReducers.OneRecord - where RowDecoder: FetchableRecord diff --git a/GRDB/ValueObservation/ValueObservation+Row.swift b/GRDB/ValueObservation/ValueObservation+Row.swift index 43f748231..9a4a6a763 100644 --- a/GRDB/ValueObservation/ValueObservation+Row.swift +++ b/GRDB/ValueObservation/ValueObservation+Row.swift @@ -59,73 +59,6 @@ extension FetchRequest where RowDecoder == Row { } } -extension ValueObservation where Reducer == Void { - - // MARK: - Row Observation - - /// Creates a ValueObservation which observes *request*, and notifies - /// fresh rows whenever the request is modified by a database transaction. - /// - /// For example: - /// - /// let request = SQLRequest(sql: "SELECT * FROM player") - /// let observation = ValueObservation.trackingAll(request) - /// - /// let observer = try observation.start(in: dbQueue) { rows: [Row] in - /// print("Players have changed") - /// } - /// - /// The returned observation has the default configuration: - /// - /// - When started with the `start(in:onError:onChange:)` method, a fresh - /// value is immediately notified on the main queue. - /// - Upon subsequent database changes, fresh values are notified on the - /// main queue. - /// - The observation lasts until the observer returned by - /// `start` is deallocated. - /// - /// - parameter request: the observed request. - /// - returns: a ValueObservation. - @available(*, deprecated, message: "Use request.observationForAll() instead") - public static func trackingAll(_ request: Request) - -> ValueObservation - where Request.RowDecoder == Row - { - return request.observationForAll() - } - - /// Creates a ValueObservation which observes *request*, and notifies a - /// fresh row whenever the request is modified by a database transaction. - /// - /// For example: - /// - /// let request = SQLRequest(sql: "SELECT * FROM player WHERE id = ?", arguments: [1]) - /// let observation = ValueObservation.trackingOne(request) - /// - /// let observer = try observation.start(in: dbQueue) { row: Row? in - /// print("Players have changed") - /// } - /// - /// The returned observation has the default configuration: - /// - /// - When started with the `start(in:onError:onChange:)` method, a fresh - /// value is immediately notified on the main queue. - /// - Upon subsequent database changes, fresh values are notified on the - /// main queue. - /// - The observation lasts until the observer returned by - /// `start` is deallocated. - /// - /// - parameter request: the observed request. - /// - returns: a ValueObservation. - @available(*, deprecated, message: "Use request.observationForFirst() instead") - public static func trackingOne(_ request: Request) - -> ValueObservation - where Request.RowDecoder == Row - { - return request.observationForFirst() - } -} - extension ValueReducers { /// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features) /// @@ -183,11 +116,3 @@ extension ValueReducers { } } } - -/// :nodoc: -@available(*, deprecated, renamed: "ValueReducers.AllRows") -public typealias RowsReducer = ValueReducers.AllRows - -/// :nodoc: -@available(*, deprecated, renamed: "ValueReducers.OneRow") -public typealias RowReducer = ValueReducers.OneRow diff --git a/GRDB/ValueObservation/ValueReducer/CompactMap.swift b/GRDB/ValueObservation/ValueReducer/CompactMap.swift index d0adb3620..00ed7eafd 100644 --- a/GRDB/ValueObservation/ValueReducer/CompactMap.swift +++ b/GRDB/ValueObservation/ValueReducer/CompactMap.swift @@ -44,7 +44,3 @@ extension ValueReducers { } } } - -/// :nodoc: -@available(*, deprecated, renamed: "ValueReducers.CompactMap") -public typealias CompactMapValueReducer = ValueReducers.CompactMap where Base: ValueReducer diff --git a/GRDB/ValueObservation/ValueReducer/Fetch.swift b/GRDB/ValueObservation/ValueReducer/Fetch.swift index 95cef1e14..0a4620ea8 100644 --- a/GRDB/ValueObservation/ValueReducer/Fetch.swift +++ b/GRDB/ValueObservation/ValueReducer/Fetch.swift @@ -20,7 +20,3 @@ extension ValueReducers { } } } - -/// :nodoc: -@available(*, deprecated, renamed: "ValueReducers.Fetch") -public typealias RawValueReducer = ValueReducers.Fetch diff --git a/GRDB/ValueObservation/ValueReducer/Map.swift b/GRDB/ValueObservation/ValueReducer/Map.swift index 5a5ef7796..2e1f1d7e9 100644 --- a/GRDB/ValueObservation/ValueReducer/Map.swift +++ b/GRDB/ValueObservation/ValueReducer/Map.swift @@ -47,7 +47,3 @@ extension ValueReducers { } } } - -/// :nodoc: -@available(*, deprecated, renamed: "ValueReducers.Map") -public typealias MapValueReducer = ValueReducers.Map where Base: ValueReducer diff --git a/GRDB/ValueObservation/ValueReducer/RemoveDuplicates.swift b/GRDB/ValueObservation/ValueReducer/RemoveDuplicates.swift index fbffa9efa..d7fd33a72 100644 --- a/GRDB/ValueObservation/ValueReducer/RemoveDuplicates.swift +++ b/GRDB/ValueObservation/ValueReducer/RemoveDuplicates.swift @@ -1,12 +1,4 @@ extension ValueObservation where Reducer: ValueReducer, Reducer.Value: Equatable { - /// Returns a ValueObservation which filters out consecutive equal values. - @available(*, deprecated, renamed: "removeDuplicates") - public func distinctUntilChanged() - -> ValueObservation> - { - return removeDuplicates() - } - /// Returns a ValueObservation which filters out consecutive equal values. public func removeDuplicates() -> ValueObservation> @@ -16,14 +8,6 @@ extension ValueObservation where Reducer: ValueReducer, Reducer.Value: Equatable } extension ValueReducer where Value: Equatable { - /// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features) - /// - /// Returns a ValueReducer which filters out consecutive equal values. - @available(*, deprecated, renamed: "removeDuplicates") - public func distinctUntilChanged() -> ValueReducers.RemoveDuplicates { - return removeDuplicates() - } - /// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features) /// /// Returns a ValueReducer which filters out consecutive equal values. @@ -63,8 +47,3 @@ extension ValueReducers { } } } - -/// :nodoc: -@available(*, deprecated, renamed: "ValueReducers.RemoveDuplicates") -public typealias DistinctUntilChangedValueReducer = ValueReducers.RemoveDuplicates - where Base: ValueReducer, Base.Value: Equatable diff --git a/Tests/GRDBTests/ValueObservationCountTests.swift b/Tests/GRDBTests/ValueObservationCountTests.swift index 8d64788b6..708ee60d6 100644 --- a/Tests/GRDBTests/ValueObservationCountTests.swift +++ b/Tests/GRDBTests/ValueObservationCountTests.swift @@ -11,40 +11,6 @@ import XCTest #endif class ValueObservationCountTests: GRDBTestCase { - func testCountDeprecated() throws { - let dbQueue = try makeDatabaseQueue() - try dbQueue.write { try $0.execute(sql: "CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT)") } - - var counts: [Int] = [] - let notificationExpectation = expectation(description: "notification") - notificationExpectation.assertForOverFulfill = true - notificationExpectation.expectedFulfillmentCount = 5 - - struct T: TableRecord { } - let observation = ValueObservation.trackingCount(T.all()) - let observer = try observation.start(in: dbQueue) { count in - counts.append(count) - notificationExpectation.fulfill() - } - try withExtendedLifetime(observer) { - try dbQueue.inDatabase { db in - try db.execute(sql: "INSERT INTO t DEFAULT VALUES") // +1 - try db.execute(sql: "UPDATE t SET id = id") // = - try db.execute(sql: "INSERT INTO t DEFAULT VALUES") // +1 - try db.inTransaction { // +1 - try db.execute(sql: "INSERT INTO t DEFAULT VALUES") - try db.execute(sql: "INSERT INTO t DEFAULT VALUES") - try db.execute(sql: "DELETE FROM t WHERE id = 1") - return .commit - } - try db.execute(sql: "DELETE FROM t WHERE id = 2") // -1 - } - - waitForExpectations(timeout: 1, handler: nil) - XCTAssertEqual(counts, [0, 1, 2, 3, 2]) - } - } - func testCount() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.write { try $0.execute(sql: "CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT)") } diff --git a/Tests/GRDBTests/ValueObservationDatabaseValueConvertibleTests.swift b/Tests/GRDBTests/ValueObservationDatabaseValueConvertibleTests.swift index 6bf7e7ca1..bdeafd4ef 100644 --- a/Tests/GRDBTests/ValueObservationDatabaseValueConvertibleTests.swift +++ b/Tests/GRDBTests/ValueObservationDatabaseValueConvertibleTests.swift @@ -28,42 +28,6 @@ private struct Name: DatabaseValueConvertible { } class ValueObservationDatabaseValueConvertibleTests: GRDBTestCase { - func testAllDeprecated() throws { - let dbQueue = try makeDatabaseQueue() - try dbQueue.write { try $0.execute(sql: "CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)") } - - var results: [[Name]] = [] - let notificationExpectation = expectation(description: "notification") - notificationExpectation.assertForOverFulfill = true - notificationExpectation.expectedFulfillmentCount = 4 - - let observation = ValueObservation.trackingAll(SQLRequest(sql: "SELECT name FROM t ORDER BY id")) - let observer = try observation.start(in: dbQueue) { names in - results.append(names) - notificationExpectation.fulfill() - } - try withExtendedLifetime(observer) { - try dbQueue.inDatabase { db in - try db.execute(sql: "INSERT INTO t (id, name) VALUES (1, 'foo')") // +1 - try db.execute(sql: "UPDATE t SET name = 'foo' WHERE id = 1") // = - try db.inTransaction { // +1 - try db.execute(sql: "INSERT INTO t (id, name) VALUES (2, 'bar')") - try db.execute(sql: "INSERT INTO t (id, name) VALUES (3, 'baz')") - try db.execute(sql: "DELETE FROM t WHERE id = 3") - return .commit - } - try db.execute(sql: "DELETE FROM t WHERE id = 1") // -1 - } - - waitForExpectations(timeout: 1, handler: nil) - XCTAssertEqual(results.map { $0.map { $0.rawValue }}, [ - [], - ["foo"], - ["foo", "bar"], - ["bar"]]) - } - } - func testAll() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.write { try $0.execute(sql: "CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)") } @@ -100,50 +64,6 @@ class ValueObservationDatabaseValueConvertibleTests: GRDBTestCase { } } - func testOneDeprecated() throws { - let dbQueue = try makeDatabaseQueue() - try dbQueue.write { try $0.execute(sql: "CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)") } - - var results: [Name?] = [] - let notificationExpectation = expectation(description: "notification") - notificationExpectation.assertForOverFulfill = true - notificationExpectation.expectedFulfillmentCount = 7 - - let observation = ValueObservation.trackingOne(SQLRequest(sql: "SELECT name FROM t ORDER BY id DESC")) - let observer = try observation.start(in: dbQueue) { name in - results.append(name) - notificationExpectation.fulfill() - } - try withExtendedLifetime(observer) { - try dbQueue.inDatabase { db in - try db.execute(sql: "INSERT INTO t (id, name) VALUES (1, 'foo')") - try db.execute(sql: "UPDATE t SET name = 'foo' WHERE id = 1") - try db.inTransaction { - try db.execute(sql: "INSERT INTO t (id, name) VALUES (2, 'bar')") - try db.execute(sql: "INSERT INTO t (id, name) VALUES (3, 'baz')") - try db.execute(sql: "DELETE FROM t WHERE id = 3") - return .commit - } - try db.execute(sql: "DELETE FROM t") - try db.execute(sql: "INSERT INTO t (id, name) VALUES (1, 'baz')") - try db.execute(sql: "UPDATE t SET name = NULL") - try db.execute(sql: "DELETE FROM t") - try db.execute(sql: "INSERT INTO t (id, name) VALUES (1, NULL)") - try db.execute(sql: "UPDATE t SET name = 'qux'") - } - - waitForExpectations(timeout: 1, handler: nil) - XCTAssertEqual(results.map { $0.map { $0.rawValue }}, [ - nil, - "foo", - "bar", - nil, - "baz", - nil, - "qux"]) - } - } - func testOne() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.write { try $0.execute(sql: "CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)") } @@ -188,42 +108,6 @@ class ValueObservationDatabaseValueConvertibleTests: GRDBTestCase { } } - func testAllOptionalDeprecated() throws { - let dbQueue = try makeDatabaseQueue() - try dbQueue.write { try $0.execute(sql: "CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)") } - - var results: [[Name?]] = [] - let notificationExpectation = expectation(description: "notification") - notificationExpectation.assertForOverFulfill = true - notificationExpectation.expectedFulfillmentCount = 4 - - let observation = ValueObservation.trackingAll(SQLRequest(sql: "SELECT name FROM t ORDER BY id")) - let observer = try observation.start(in: dbQueue) { names in - results.append(names) - notificationExpectation.fulfill() - } - try withExtendedLifetime(observer) { - try dbQueue.inDatabase { db in - try db.execute(sql: "INSERT INTO t (id, name) VALUES (1, 'foo')") // +1 - try db.execute(sql: "UPDATE t SET name = 'foo' WHERE id = 1") // = - try db.inTransaction { // +1 - try db.execute(sql: "INSERT INTO t (id, name) VALUES (2, NULL)") - try db.execute(sql: "INSERT INTO t (id, name) VALUES (3, 'baz')") - try db.execute(sql: "DELETE FROM t WHERE id = 3") - return .commit - } - try db.execute(sql: "DELETE FROM t WHERE id = 1") // -1 - } - - waitForExpectations(timeout: 1, handler: nil) - XCTAssertEqual(results.map { $0.map { $0?.rawValue }}, [ - [], - ["foo"], - ["foo", nil], - [nil]]) - } - } - func testAllOptional() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.write { try $0.execute(sql: "CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)") } diff --git a/Tests/GRDBTests/ValueObservationFetchTests.swift b/Tests/GRDBTests/ValueObservationFetchTests.swift index b53bb44f5..11f332597 100644 --- a/Tests/GRDBTests/ValueObservationFetchTests.swift +++ b/Tests/GRDBTests/ValueObservationFetchTests.swift @@ -52,38 +52,6 @@ class ValueObservationFetchTests: GRDBTestCase { try test(makeDatabasePool()) } - func testDistinctUntilChangedDeprecated() throws { - func test(_ dbWriter: DatabaseWriter) throws { - try dbWriter.write { try $0.execute(sql: "CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT)") } - - var counts: [Int] = [] - let notificationExpectation = expectation(description: "notification") - notificationExpectation.assertForOverFulfill = true - notificationExpectation.expectedFulfillmentCount = 3 - - let observation = ValueObservation.tracking(DatabaseRegion.fullDatabase, fetch: { - try Int.fetchOne($0, sql: "SELECT COUNT(*) FROM t")! - }).distinctUntilChanged() - let observer = try observation.start(in: dbWriter) { count in - counts.append(count) - notificationExpectation.fulfill() - } - try withExtendedLifetime(observer) { - try dbWriter.writeWithoutTransaction { db in - try db.execute(sql: "INSERT INTO t DEFAULT VALUES") - try db.execute(sql: "UPDATE t SET id = id") - try db.execute(sql: "INSERT INTO t DEFAULT VALUES") - } - - waitForExpectations(timeout: 1, handler: nil) - XCTAssertEqual(counts, [0, 1, 2]) - } - } - - try test(makeDatabaseQueue()) - try test(makeDatabasePool()) - } - func testRemoveDuplicated() throws { func test(_ dbWriter: DatabaseWriter) throws { try dbWriter.write { try $0.execute(sql: "CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT)") } diff --git a/Tests/GRDBTests/ValueObservationQueryInterfaceRequestTests.swift b/Tests/GRDBTests/ValueObservationQueryInterfaceRequestTests.swift index 8deae9f20..afd95067f 100644 --- a/Tests/GRDBTests/ValueObservationQueryInterfaceRequestTests.swift +++ b/Tests/GRDBTests/ValueObservationQueryInterfaceRequestTests.swift @@ -49,41 +49,6 @@ class ValueObservationQueryInterfaceRequestTests: GRDBTestCase { } } - func testOneRowWithPrefetchedRowsDeprecated() throws { - let dbQueue = try makeDatabaseQueue() - - var results: [Row?] = [] - let notificationExpectation = expectation(description: "notification") - notificationExpectation.assertForOverFulfill = true - notificationExpectation.expectedFulfillmentCount = 2 - - let request = Parent - .including(all: Parent.children.orderByPrimaryKey()) - .orderByPrimaryKey() - .asRequest(of: Row.self) - let observation = ValueObservation.trackingOne(request) - let observer = try observation.start(in: dbQueue) { row in - results.append(row) - notificationExpectation.fulfill() - } - try withExtendedLifetime(observer) { - try dbQueue.inDatabase { db in - try db.execute(sql: "DELETE FROM child") - } - - waitForExpectations(timeout: 1, handler: nil) - XCTAssertEqual(results.count, 2) - - XCTAssertEqual(results[0]!.unscoped, ["id": 1, "name": "foo"]) - XCTAssertEqual(results[0]!.prefetchedRows["children"], [ - ["id": 1, "parentId": 1, "name": "fooA", "grdb_parentId": 1], - ["id": 2, "parentId": 1, "name": "fooB", "grdb_parentId": 1]]) - - XCTAssertEqual(results[1]!.unscoped, ["id": 1, "name": "foo"]) - XCTAssertEqual(results[1]!.prefetchedRows["children"], []) - } - } - func testOneRowWithPrefetchedRows() throws { let dbQueue = try makeDatabaseQueue() @@ -118,49 +83,7 @@ class ValueObservationQueryInterfaceRequestTests: GRDBTestCase { XCTAssertEqual(results[1]!.prefetchedRows["children"], []) } } - - func testAllRowsWithPrefetchedRowsDeprecated() throws { - let dbQueue = try makeDatabaseQueue() - - var results: [[Row]] = [] - let notificationExpectation = expectation(description: "notification") - notificationExpectation.assertForOverFulfill = true - notificationExpectation.expectedFulfillmentCount = 2 - - let request = Parent - .including(all: Parent.children.orderByPrimaryKey()) - .orderByPrimaryKey() - .asRequest(of: Row.self) - let observation = ValueObservation.trackingAll(request) - let observer = try observation.start(in: dbQueue) { rows in - results.append(rows) - notificationExpectation.fulfill() - } - try withExtendedLifetime(observer) { - try dbQueue.inDatabase { db in - try db.execute(sql: "DELETE FROM child") - } - - waitForExpectations(timeout: 1, handler: nil) - XCTAssertEqual(results.count, 2) - - XCTAssertEqual(results[0].count, 2) - XCTAssertEqual(results[0][0].unscoped, ["id": 1, "name": "foo"]) - XCTAssertEqual(results[0][0].prefetchedRows["children"], [ - ["id": 1, "parentId": 1, "name": "fooA", "grdb_parentId": 1], - ["id": 2, "parentId": 1, "name": "fooB", "grdb_parentId": 1]]) - XCTAssertEqual(results[0][1].unscoped, ["id": 2, "name": "bar"]) - XCTAssertEqual(results[0][1].prefetchedRows["children"], [ - ["id": 3, "parentId": 2, "name": "barA", "grdb_parentId": 2]]) - - XCTAssertEqual(results[1].count, 2) - XCTAssertEqual(results[1][0].unscoped, ["id": 1, "name": "foo"]) - XCTAssertEqual(results[1][0].prefetchedRows["children"], []) - XCTAssertEqual(results[1][1].unscoped, ["id": 2, "name": "bar"]) - XCTAssertEqual(results[1][1].prefetchedRows["children"], []) - } - } - + func testAllRowsWithPrefetchedRows() throws { let dbQueue = try makeDatabaseQueue() @@ -203,43 +126,6 @@ class ValueObservationQueryInterfaceRequestTests: GRDBTestCase { } } - func testOneRecordWithPrefetchedRowsDeprecated() throws { - let dbQueue = try makeDatabaseQueue() - - var results: [ParentInfo?] = [] - let notificationExpectation = expectation(description: "notification") - notificationExpectation.assertForOverFulfill = true - notificationExpectation.expectedFulfillmentCount = 2 - - let request = Parent - .including(all: Parent.children.orderByPrimaryKey()) - .orderByPrimaryKey() - .asRequest(of: ParentInfo.self) - let observation = ValueObservation.trackingOne(request) - let observer = try observation.start(in: dbQueue) { parentInfo in - results.append(parentInfo) - notificationExpectation.fulfill() - } - try withExtendedLifetime(observer) { - try dbQueue.inDatabase { db in - try db.execute(sql: "DELETE FROM child") - } - - waitForExpectations(timeout: 1, handler: nil) - XCTAssertEqual(results, [ - ParentInfo( - parent: Parent(id: 1, name: "foo"), - children: [ - Child(id: 1, parentId: 1, name: "fooA"), - Child(id: 2, parentId: 1, name: "fooB"), - ]), - ParentInfo( - parent: Parent(id: 1, name: "foo"), - children: []), - ]) - } - } - func testOneRecordWithPrefetchedRows() throws { let dbQueue = try makeDatabaseQueue() @@ -277,55 +163,6 @@ class ValueObservationQueryInterfaceRequestTests: GRDBTestCase { } } - func testAllRecordsWithPrefetchedRowsDeprecated() throws { - let dbQueue = try makeDatabaseQueue() - - var results: [[ParentInfo]] = [] - let notificationExpectation = expectation(description: "notification") - notificationExpectation.assertForOverFulfill = true - notificationExpectation.expectedFulfillmentCount = 2 - - let request = Parent - .including(all: Parent.children.orderByPrimaryKey()) - .orderByPrimaryKey() - .asRequest(of: ParentInfo.self) - let observation = ValueObservation.trackingAll(request) - let observer = try observation.start(in: dbQueue) { parentInfos in - results.append(parentInfos) - notificationExpectation.fulfill() - } - try withExtendedLifetime(observer) { - try dbQueue.inDatabase { db in - try db.execute(sql: "DELETE FROM child") - } - - waitForExpectations(timeout: 1, handler: nil) - XCTAssertEqual(results, [ - [ - ParentInfo( - parent: Parent(id: 1, name: "foo"), - children: [ - Child(id: 1, parentId: 1, name: "fooA"), - Child(id: 2, parentId: 1, name: "fooB"), - ]), - ParentInfo( - parent: Parent(id: 2, name: "bar"), - children: [ - Child(id: 3, parentId: 2, name: "barA"), - ]), - ], - [ - ParentInfo( - parent: Parent(id: 1, name: "foo"), - children: []), - ParentInfo( - parent: Parent(id: 2, name: "bar"), - children: []), - ], - ]) - } - } - func testAllRecordsWithPrefetchedRows() throws { let dbQueue = try makeDatabaseQueue() diff --git a/Tests/GRDBTests/ValueObservationRecordTests.swift b/Tests/GRDBTests/ValueObservationRecordTests.swift index a5e9b6e80..4de5c0ff3 100644 --- a/Tests/GRDBTests/ValueObservationRecordTests.swift +++ b/Tests/GRDBTests/ValueObservationRecordTests.swift @@ -26,42 +26,6 @@ private struct Player: TableRecord, FetchableRecord { } class ValueObservationRecordTests: GRDBTestCase { - func testAllDeprecated() throws { - let dbQueue = try makeDatabaseQueue() - try dbQueue.write { try $0.execute(sql: "CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)") } - - var results: [[Player]] = [] - let notificationExpectation = expectation(description: "notification") - notificationExpectation.assertForOverFulfill = true - notificationExpectation.expectedFulfillmentCount = 4 - - let observation = ValueObservation.trackingAll(SQLRequest(sql: "SELECT * FROM t ORDER BY id")) - let observer = try observation.start(in: dbQueue) { players in - results.append(players) - notificationExpectation.fulfill() - } - try withExtendedLifetime(observer) { - try dbQueue.inDatabase { db in - try db.execute(sql: "INSERT INTO t (id, name) VALUES (1, 'foo')") // +1 - try db.execute(sql: "UPDATE t SET name = 'foo' WHERE id = 1") // = - try db.inTransaction { // +1 - try db.execute(sql: "INSERT INTO t (id, name) VALUES (2, 'bar')") - try db.execute(sql: "INSERT INTO t (id, name) VALUES (3, 'baz')") - try db.execute(sql: "DELETE FROM t WHERE id = 3") - return .commit - } - try db.execute(sql: "DELETE FROM t WHERE id = 1") // -1 - } - - waitForExpectations(timeout: 1, handler: nil) - XCTAssertEqual(results.map { $0.map { $0.row }}, [ - [], - [["id":1, "name":"foo"]], - [["id":1, "name":"foo"], ["id":2, "name":"bar"]], - [["id":2, "name":"bar"]]]) - } - } - func testAll() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.write { try $0.execute(sql: "CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)") } @@ -133,43 +97,7 @@ class ValueObservationRecordTests: GRDBTestCase { [["id":2, "name":"bar"]]]) } } - - func testOneDeprecated() throws { - let dbQueue = try makeDatabaseQueue() - try dbQueue.write { try $0.execute(sql: "CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)") } - - var results: [Player?] = [] - let notificationExpectation = expectation(description: "notification") - notificationExpectation.assertForOverFulfill = true - notificationExpectation.expectedFulfillmentCount = 4 - - let observation = ValueObservation.trackingOne(SQLRequest(sql: "SELECT * FROM t ORDER BY id DESC")) - let observer = try observation.start(in: dbQueue) { player in - results.append(player) - notificationExpectation.fulfill() - } - try withExtendedLifetime(observer) { - try dbQueue.inDatabase { db in - try db.execute(sql: "INSERT INTO t (id, name) VALUES (1, 'foo')") // +1 - try db.execute(sql: "UPDATE t SET name = 'foo' WHERE id = 1") // = - try db.inTransaction { // +1 - try db.execute(sql: "INSERT INTO t (id, name) VALUES (2, 'bar')") - try db.execute(sql: "INSERT INTO t (id, name) VALUES (3, 'baz')") - try db.execute(sql: "DELETE FROM t WHERE id = 3") - return .commit - } - try db.execute(sql: "DELETE FROM t") // -1 - } - - waitForExpectations(timeout: 1, handler: nil) - XCTAssertEqual(results.map { $0.map { $0.row }}, [ - nil, - ["id":1, "name":"foo"], - ["id":2, "name":"bar"], - nil]) - } - } - + func testOne() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.write { try $0.execute(sql: "CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)") } diff --git a/Tests/GRDBTests/ValueObservationRowTests.swift b/Tests/GRDBTests/ValueObservationRowTests.swift index 4e3c8dc58..b152099b1 100644 --- a/Tests/GRDBTests/ValueObservationRowTests.swift +++ b/Tests/GRDBTests/ValueObservationRowTests.swift @@ -11,42 +11,6 @@ import XCTest #endif class ValueObservationRowTests: GRDBTestCase { - func testAllDeprecated() throws { - let dbQueue = try makeDatabaseQueue() - try dbQueue.write { try $0.execute(sql: "CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)") } - - var results: [[Row]] = [] - let notificationExpectation = expectation(description: "notification") - notificationExpectation.assertForOverFulfill = true - notificationExpectation.expectedFulfillmentCount = 4 - - let observation = ValueObservation.trackingAll(SQLRequest(sql: "SELECT * FROM t ORDER BY id")) - let observer = try observation.start(in: dbQueue) { rows in - results.append(rows) - notificationExpectation.fulfill() - } - try withExtendedLifetime(observer) { - try dbQueue.inDatabase { db in - try db.execute(sql: "INSERT INTO t (id, name) VALUES (1, 'foo')") // +1 - try db.execute(sql: "UPDATE t SET name = 'foo' WHERE id = 1") // = - try db.inTransaction { // +1 - try db.execute(sql: "INSERT INTO t (id, name) VALUES (2, 'bar')") - try db.execute(sql: "INSERT INTO t (id, name) VALUES (3, 'baz')") - try db.execute(sql: "DELETE FROM t WHERE id = 3") - return .commit - } - try db.execute(sql: "DELETE FROM t WHERE id = 1") // -1 - } - - waitForExpectations(timeout: 1, handler: nil) - XCTAssertEqual(results, [ - [], - [["id":1, "name":"foo"]], - [["id":1, "name":"foo"], ["id":2, "name":"bar"]], - [["id":2, "name":"bar"]]]) - } - } - func testAll() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.write { try $0.execute(sql: "CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)") } @@ -83,42 +47,6 @@ class ValueObservationRowTests: GRDBTestCase { } } - func testOneDeprecated() throws { - let dbQueue = try makeDatabaseQueue() - try dbQueue.write { try $0.execute(sql: "CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)") } - - var results: [Row?] = [] - let notificationExpectation = expectation(description: "notification") - notificationExpectation.assertForOverFulfill = true - notificationExpectation.expectedFulfillmentCount = 4 - - let observation = ValueObservation.trackingOne(SQLRequest(sql: "SELECT * FROM t ORDER BY id DESC")) - let observer = try observation.start(in: dbQueue) { row in - results.append(row) - notificationExpectation.fulfill() - } - try withExtendedLifetime(observer) { - try dbQueue.inDatabase { db in - try db.execute(sql: "INSERT INTO t (id, name) VALUES (1, 'foo')") // +1 - try db.execute(sql: "UPDATE t SET name = 'foo' WHERE id = 1") // = - try db.inTransaction { // +1 - try db.execute(sql: "INSERT INTO t (id, name) VALUES (2, 'bar')") - try db.execute(sql: "INSERT INTO t (id, name) VALUES (3, 'baz')") - try db.execute(sql: "DELETE FROM t WHERE id = 3") - return .commit - } - try db.execute(sql: "DELETE FROM t") // -1 - } - } - - waitForExpectations(timeout: 1, handler: nil) - XCTAssertEqual(results, [ - nil, - ["id":1, "name":"foo"], - ["id":2, "name":"bar"], - nil]) - } - func testOne() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.write { try $0.execute(sql: "CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)") }