mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-30 04:28:44 +00:00
Remove deprecated ValueObservation methods
This commit is contained in:
1 parent
b9d4a5215a
commit
5dd86d2453
15 files changed
+64
-830
No files matched your search
@@ -88,6 +88,68 @@ extension Statement {
|
||||
{ preconditionFailure() }
|
||||
}
|
||||
|
||||
extension ValueObservation where Reducer == Void {
|
||||
@available(*, unavailable, message: "Use request.observationForCount() instead")
|
||||
public static func trackingCount<Request: FetchRequest>(_ request: Request)
|
||||
-> ValueObservation<ValueReducers.RemoveDuplicates<ValueReducers.Fetch<Int>>>
|
||||
{ preconditionFailure() }
|
||||
|
||||
@available(*, unavailable, message: "Use request.observationForAll() instead")
|
||||
public static func trackingAll<Request: FetchRequest>(_ request: Request)
|
||||
-> ValueObservation<ValueReducers.AllValues<Request.RowDecoder>>
|
||||
where Request.RowDecoder: DatabaseValueConvertible
|
||||
{ preconditionFailure() }
|
||||
|
||||
@available(*, unavailable, message: "Use request.observationForFirst() instead")
|
||||
public static func trackingOne<Request: FetchRequest>(_ request: Request)
|
||||
-> ValueObservation<ValueReducers.AllValues<Request.RowDecoder>>
|
||||
where Request.RowDecoder: DatabaseValueConvertible
|
||||
{ preconditionFailure() }
|
||||
|
||||
@available(*, unavailable, message: "Use request.observationForAll() instead")
|
||||
public static func trackingAll<Request: FetchRequest>(_ request: Request)
|
||||
-> ValueObservation<ValueReducers.AllOptionalValues<Request.RowDecoder._Wrapped>>
|
||||
where Request.RowDecoder: _OptionalProtocol,
|
||||
Request.RowDecoder._Wrapped: DatabaseValueConvertible
|
||||
{ preconditionFailure() }
|
||||
|
||||
@available(*, unavailable, message: "Use request.observationForAll() instead")
|
||||
public static func trackingAll<Request: FetchRequest>(_ request: Request)
|
||||
-> ValueObservation<ValueReducers.AllRecords<Request.RowDecoder>>
|
||||
where Request.RowDecoder: FetchableRecord
|
||||
{ preconditionFailure() }
|
||||
|
||||
@available(*, unavailable, message: "Use request.observationForFirst() instead")
|
||||
public static func trackingOne<Request: FetchRequest>(_ request: Request) ->
|
||||
ValueObservation<ValueReducers.OneRecord<Request.RowDecoder>>
|
||||
where Request.RowDecoder: FetchableRecord
|
||||
{ preconditionFailure() }
|
||||
|
||||
@available(*, unavailable, message: "Use request.observationForAll() instead")
|
||||
public static func trackingAll<Request: FetchRequest>(_ request: Request)
|
||||
-> ValueObservation<ValueReducers.AllRows>
|
||||
where Request.RowDecoder == Row
|
||||
{ preconditionFailure() }
|
||||
|
||||
@available(*, unavailable, message: "Use request.observationForFirst() instead")
|
||||
public static func trackingOne<Request: FetchRequest>(_ request: Request)
|
||||
-> ValueObservation<ValueReducers.OneRow>
|
||||
where Request.RowDecoder == Row
|
||||
{ preconditionFailure() }
|
||||
}
|
||||
|
||||
extension ValueObservation where Reducer: ValueReducer, Reducer.Value: Equatable {
|
||||
@available(*, unavailable, renamed: "removeDuplicates")
|
||||
public func distinctUntilChanged() -> ValueObservation<ValueReducers.RemoveDuplicates<Reducer>>
|
||||
{ preconditionFailure() }
|
||||
}
|
||||
|
||||
extension ValueReducer where Value: Equatable {
|
||||
@available(*, unavailable, renamed: "removeDuplicates")
|
||||
public func distinctUntilChanged() -> ValueReducers.RemoveDuplicates<Self>
|
||||
{ preconditionFailure() }
|
||||
}
|
||||
|
||||
#if SQLITE_HAS_CODEC
|
||||
extension Configuration {
|
||||
@available(*, unavailable, message: "Use Database.usePassphrase(_:) in Configuration.prepareDatabase instead.")
|
||||
|
||||
@@ -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: FetchRequest>(_ request: Request)
|
||||
-> ValueObservation<ValueReducers.RemoveDuplicates<ValueReducers.Fetch<Int>>>
|
||||
{
|
||||
return request.observationForCount()
|
||||
}
|
||||
}
|
||||
@@ -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: FetchRequest>(_ request: Request)
|
||||
-> ValueObservation<DatabaseValuesReducer<Request.RowDecoder>>
|
||||
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: FetchRequest>(_ request: Request)
|
||||
-> ValueObservation<DatabaseValueReducer<Request.RowDecoder>>
|
||||
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<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: FetchRequest>(_ request: Request)
|
||||
-> ValueObservation<OptionalDatabaseValuesReducer<Request.RowDecoder._Wrapped>>
|
||||
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<RowDecoder> = ValueReducers.AllValues<RowDecoder>
|
||||
where RowDecoder: DatabaseValueConvertible
|
||||
|
||||
/// :nodoc:
|
||||
@available(*, deprecated, renamed: "ValueReducers.OneValue")
|
||||
public typealias DatabaseValueReducer<RowDecoder> = ValueReducers.OneValue<RowDecoder>
|
||||
where RowDecoder: DatabaseValueConvertible
|
||||
|
||||
/// :nodoc:
|
||||
@available(*, deprecated, renamed: "ValueReducers.AllOptionalValues")
|
||||
public typealias OptionalDatabaseValuesReducer<RowDecoder> = ValueReducers.AllOptionalValues<RowDecoder>
|
||||
where RowDecoder: DatabaseValueConvertible
|
||||
@@ -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: FetchRequest>(_ request: Request)
|
||||
-> ValueObservation<FetchableRecordsReducer<Request.RowDecoder>>
|
||||
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: FetchRequest>(_ request: Request) ->
|
||||
ValueObservation<FetchableRecordReducer<Request.RowDecoder>>
|
||||
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<RowDecoder>
|
||||
= ValueReducers.AllRecords<RowDecoder>
|
||||
where RowDecoder: FetchableRecord
|
||||
|
||||
/// :nodoc:
|
||||
@available(*, deprecated, renamed: "ValueReducers.OneRecord")
|
||||
public typealias FetchableRecordReducer<RowDecoder>
|
||||
= ValueReducers.OneRecord<RowDecoder>
|
||||
where RowDecoder: FetchableRecord
|
||||
@@ -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<Row>(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: FetchRequest>(_ request: Request)
|
||||
-> ValueObservation<RowsReducer>
|
||||
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<Row>(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: FetchRequest>(_ request: Request)
|
||||
-> ValueObservation<RowReducer>
|
||||
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
|
||||
@@ -44,7 +44,3 @@ extension ValueReducers {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
@available(*, deprecated, renamed: "ValueReducers.CompactMap")
|
||||
public typealias CompactMapValueReducer<Base, Value> = ValueReducers.CompactMap<Base, Value> where Base: ValueReducer
|
||||
@@ -20,7 +20,3 @@ extension ValueReducers {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
@available(*, deprecated, renamed: "ValueReducers.Fetch")
|
||||
public typealias RawValueReducer<Value> = ValueReducers.Fetch<Value>
|
||||
@@ -47,7 +47,3 @@ extension ValueReducers {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
@available(*, deprecated, renamed: "ValueReducers.Map")
|
||||
public typealias MapValueReducer<Base, Value> = ValueReducers.Map<Base, Value> where Base: ValueReducer
|
||||
@@ -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<ValueReducers.RemoveDuplicates<Reducer>>
|
||||
{
|
||||
return removeDuplicates()
|
||||
}
|
||||
|
||||
/// Returns a ValueObservation which filters out consecutive equal values.
|
||||
public func removeDuplicates()
|
||||
-> ValueObservation<ValueReducers.RemoveDuplicates<Reducer>>
|
||||
@@ -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<Self> {
|
||||
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<Base> = ValueReducers.RemoveDuplicates<Base>
|
||||
where Base: ValueReducer, Base.Value: Equatable
|
||||
@@ -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)") }
|
||||
|
||||
@@ -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<Name>(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<Name>(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<Name?>(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)") }
|
||||
|
||||
@@ -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)") }
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
@@ -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<Player>(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<Player>(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)") }
|
||||
|
||||
@@ -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<Row>(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<Row>(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)") }
|
||||
|
||||
Reference in new issue
Block a user