mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-24 04:07:47 +00:00
Mute compiler warning until language is fixed
The wrong warning is "Converting non-sendable function value to '@Sendable (Database) throws -> Void' may introduce data races" https://github.com/apple/swift/issues/71541
This commit is contained in:
1 parent
22a50a027a
commit
bb22d9eced
22 files changed
+145
-79
No files matched your search
@@ -34,7 +34,7 @@ class ValueObservationPublisherTests : XCTestCase {
|
||||
|
||||
func test(writer: some DatabaseWriter) throws {
|
||||
let publisher = ValueObservation
|
||||
.trackingConstantRegion(Player.fetchCount)
|
||||
.trackingConstantRegion { try Player.fetchCount($0) }
|
||||
.publisher(in: writer)
|
||||
let recorder = publisher.record()
|
||||
|
||||
@@ -79,7 +79,7 @@ class ValueObservationPublisherTests : XCTestCase {
|
||||
let expectation = self.expectation(description: "")
|
||||
let semaphore = DispatchSemaphore(value: 0)
|
||||
let cancellable = ValueObservation
|
||||
.trackingConstantRegion(Player.fetchCount)
|
||||
.trackingConstantRegion { try Player.fetchCount($0) }
|
||||
.publisher(in: writer)
|
||||
.sink(
|
||||
receiveCompletion: { _ in },
|
||||
@@ -138,7 +138,7 @@ class ValueObservationPublisherTests : XCTestCase {
|
||||
|
||||
func test(writer: some DatabaseWriter) throws {
|
||||
let publisher = ValueObservation
|
||||
.trackingConstantRegion(Player.fetchCount)
|
||||
.trackingConstantRegion { try Player.fetchCount($0) }
|
||||
.publisher(in: writer, scheduling: .immediate)
|
||||
let recorder = publisher.record()
|
||||
|
||||
@@ -191,7 +191,7 @@ class ValueObservationPublisherTests : XCTestCase {
|
||||
})
|
||||
|
||||
let observationCancellable = ValueObservation
|
||||
.trackingConstantRegion(Player.fetchCount)
|
||||
.trackingConstantRegion { try Player.fetchCount($0) }
|
||||
.publisher(in: writer, scheduling: .immediate)
|
||||
.subscribe(testSubject)
|
||||
|
||||
@@ -284,7 +284,7 @@ class ValueObservationPublisherTests : XCTestCase {
|
||||
receiveValue: { _ in expectation.fulfill() })
|
||||
|
||||
ValueObservation
|
||||
.trackingConstantRegion(Player.fetchCount)
|
||||
.trackingConstantRegion { try Player.fetchCount($0) }
|
||||
.publisher(in: writer)
|
||||
.subscribe(subscriber)
|
||||
|
||||
@@ -321,7 +321,7 @@ class ValueObservationPublisherTests : XCTestCase {
|
||||
})
|
||||
|
||||
ValueObservation
|
||||
.trackingConstantRegion(Player.fetchCount)
|
||||
.trackingConstantRegion { try Player.fetchCount($0) }
|
||||
.publisher(in: writer)
|
||||
.subscribe(subscriber)
|
||||
|
||||
@@ -360,7 +360,7 @@ class ValueObservationPublisherTests : XCTestCase {
|
||||
receiveValue: { _ in expectation.fulfill() })
|
||||
|
||||
ValueObservation
|
||||
.trackingConstantRegion(Player.fetchCount)
|
||||
.trackingConstantRegion { try Player.fetchCount($0) }
|
||||
.publisher(in: writer, scheduling: .immediate /* make sure we get the initial db state */)
|
||||
.subscribe(subscriber)
|
||||
|
||||
@@ -404,7 +404,7 @@ class ValueObservationPublisherTests : XCTestCase {
|
||||
})
|
||||
|
||||
ValueObservation
|
||||
.trackingConstantRegion(Player.fetchCount)
|
||||
.trackingConstantRegion { try Player.fetchCount($0) }
|
||||
.publisher(in: writer, scheduling: .immediate /* make sure we get two db states */)
|
||||
.subscribe(subscriber)
|
||||
|
||||
|
||||
@@ -131,7 +131,9 @@ class RecordEditedTests: GRDBTestCase {
|
||||
|
||||
override func setup(_ dbWriter: some DatabaseWriter) throws {
|
||||
var migrator = DatabaseMigrator()
|
||||
migrator.registerMigration("createPerson", migrate: Person.setup)
|
||||
migrator.registerMigration("createPerson") {
|
||||
try Person.setup(inDatabase: $0)
|
||||
}
|
||||
try migrator.migrate(dbWriter)
|
||||
}
|
||||
|
||||
|
||||
@@ -48,7 +48,9 @@ class RecordMinimalNonOptionalPrimaryKeySingleTests: GRDBTestCase {
|
||||
|
||||
override func setup(_ dbWriter: some DatabaseWriter) throws {
|
||||
var migrator = DatabaseMigrator()
|
||||
migrator.registerMigration("createMinimalNonOptionalPrimaryKeySingle", migrate: MinimalNonOptionalPrimaryKeySingle.setup)
|
||||
migrator.registerMigration("createMinimalNonOptionalPrimaryKeySingle") {
|
||||
try MinimalNonOptionalPrimaryKeySingle.setup(inDatabase: $0)
|
||||
}
|
||||
try migrator.migrate(dbWriter)
|
||||
}
|
||||
|
||||
|
||||
@@ -52,7 +52,9 @@ class RecordMinimalPrimaryKeyRowIDTests : GRDBTestCase {
|
||||
|
||||
override func setup(_ dbWriter: some DatabaseWriter) throws {
|
||||
var migrator = DatabaseMigrator()
|
||||
migrator.registerMigration("createMinimalRowID", migrate: MinimalRowID.setup)
|
||||
migrator.registerMigration("createMinimalRowID") {
|
||||
try MinimalRowID.setup(inDatabase: $0)
|
||||
}
|
||||
try migrator.migrate(dbWriter)
|
||||
}
|
||||
|
||||
|
||||
@@ -49,7 +49,9 @@ class RecordMinimalPrimaryKeySingleTests: GRDBTestCase {
|
||||
|
||||
override func setup(_ dbWriter: some DatabaseWriter) throws {
|
||||
var migrator = DatabaseMigrator()
|
||||
migrator.registerMigration("createMinimalSingle", migrate: MinimalSingle.setup)
|
||||
migrator.registerMigration("createMinimalSingle") {
|
||||
try MinimalSingle.setup(inDatabase: $0)
|
||||
}
|
||||
try migrator.migrate(dbWriter)
|
||||
}
|
||||
|
||||
|
||||
@@ -84,7 +84,9 @@ class RecordPrimaryKeyHiddenRowIDTests : GRDBTestCase {
|
||||
|
||||
override func setup(_ dbWriter: some DatabaseWriter) throws {
|
||||
var migrator = DatabaseMigrator()
|
||||
migrator.registerMigration("createPerson", migrate: Person.setup)
|
||||
migrator.registerMigration("createPerson") {
|
||||
try Person.setup(inDatabase: $0)
|
||||
}
|
||||
try migrator.migrate(dbWriter)
|
||||
}
|
||||
|
||||
|
||||
@@ -61,7 +61,9 @@ class RecordPrimaryKeyMultipleTests: GRDBTestCase {
|
||||
|
||||
override func setup(_ dbWriter: some DatabaseWriter) throws {
|
||||
var migrator = DatabaseMigrator()
|
||||
migrator.registerMigration("createCitizenship", migrate: Citizenship.setup)
|
||||
migrator.registerMigration("createCitizenship") {
|
||||
try Citizenship.setup(inDatabase: $0)
|
||||
}
|
||||
try migrator.migrate(dbWriter)
|
||||
}
|
||||
|
||||
|
||||
@@ -58,7 +58,9 @@ class RecordPrimaryKeyNoneTests: GRDBTestCase {
|
||||
|
||||
override func setup(_ dbWriter: some DatabaseWriter) throws {
|
||||
var migrator = DatabaseMigrator()
|
||||
migrator.registerMigration("createItem", migrate: Item.setup)
|
||||
migrator.registerMigration("createItem") {
|
||||
try Item.setup(inDatabase: $0)
|
||||
}
|
||||
try migrator.migrate(dbWriter)
|
||||
}
|
||||
|
||||
|
||||
@@ -78,7 +78,9 @@ class RecordPrimaryKeyRowIDTests: GRDBTestCase {
|
||||
|
||||
override func setup(_ dbWriter: some DatabaseWriter) throws {
|
||||
var migrator = DatabaseMigrator()
|
||||
migrator.registerMigration("createPerson", migrate: Person.setup)
|
||||
migrator.registerMigration("createPerson") {
|
||||
try Person.setup(inDatabase: $0)
|
||||
}
|
||||
try migrator.migrate(dbWriter)
|
||||
}
|
||||
|
||||
|
||||
@@ -51,7 +51,9 @@ class RecordPrimaryKeySingleTests: GRDBTestCase {
|
||||
|
||||
override func setup(_ dbWriter: some DatabaseWriter) throws {
|
||||
var migrator = DatabaseMigrator()
|
||||
migrator.registerMigration("createPet", migrate: Pet.setup)
|
||||
migrator.registerMigration("createPet") {
|
||||
try Pet.setup(inDatabase: $0)
|
||||
}
|
||||
try migrator.migrate(dbWriter)
|
||||
}
|
||||
|
||||
|
||||
@@ -50,7 +50,9 @@ class RecordPrimaryKeySingleWithReplaceConflictResolutionTests: GRDBTestCase {
|
||||
|
||||
override func setup(_ dbWriter: some DatabaseWriter) throws {
|
||||
var migrator = DatabaseMigrator()
|
||||
migrator.registerMigration("createEmail", migrate: Email.setup)
|
||||
migrator.registerMigration("createEmail") {
|
||||
try Email.setup(inDatabase: $0)
|
||||
}
|
||||
try migrator.migrate(dbWriter)
|
||||
}
|
||||
|
||||
|
||||
@@ -105,7 +105,9 @@ class RecordSubClassTests: GRDBTestCase {
|
||||
|
||||
override func setup(_ dbWriter: some DatabaseWriter) throws {
|
||||
var migrator = DatabaseMigrator()
|
||||
migrator.registerMigration("createPerson", migrate: Person.setup)
|
||||
migrator.registerMigration("createPerson") {
|
||||
try Person.setup(inDatabase: $0)
|
||||
}
|
||||
try migrator.migrate(dbWriter)
|
||||
}
|
||||
|
||||
|
||||
@@ -48,7 +48,9 @@ class RecordWithColumnNameManglingTests: GRDBTestCase {
|
||||
|
||||
override func setup(_ dbWriter: some DatabaseWriter) throws {
|
||||
var migrator = DatabaseMigrator()
|
||||
migrator.registerMigration("createBadlyMangledStuff", migrate: BadlyMangledStuff.setup)
|
||||
migrator.registerMigration("createBadlyMangledStuff") {
|
||||
try BadlyMangledStuff.setup(inDatabase: $0)
|
||||
}
|
||||
try migrator.migrate(dbWriter)
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,9 @@ class SharedValueObservationTests: GRDBTestCase {
|
||||
|
||||
let log = Log()
|
||||
var sharedObservation: SharedValueObservation<Int>? = ValueObservation
|
||||
.tracking(Table("player").fetchCount)
|
||||
.tracking {
|
||||
try Table("player").fetchCount($0)
|
||||
}
|
||||
.print(to: log)
|
||||
.shared(
|
||||
in: dbQueue,
|
||||
@@ -65,7 +67,9 @@ class SharedValueObservationTests: GRDBTestCase {
|
||||
|
||||
let log = Log()
|
||||
var sharedObservation: SharedValueObservation<Int>? = ValueObservation
|
||||
.tracking(Table("player").fetchCount)
|
||||
.tracking {
|
||||
try Table("player").fetchCount($0)
|
||||
}
|
||||
.print(to: log)
|
||||
.shared(
|
||||
in: dbQueue,
|
||||
@@ -117,7 +121,9 @@ class SharedValueObservationTests: GRDBTestCase {
|
||||
}
|
||||
|
||||
let publisher = ValueObservation
|
||||
.tracking(Table("player").fetchCount)
|
||||
.tracking {
|
||||
try Table("player").fetchCount($0)
|
||||
}
|
||||
.shared(
|
||||
in: dbQueue,
|
||||
scheduling: .immediate)
|
||||
@@ -149,7 +155,9 @@ class SharedValueObservationTests: GRDBTestCase {
|
||||
|
||||
let log = Log()
|
||||
var sharedObservation: SharedValueObservation<Int>? = ValueObservation
|
||||
.tracking(Table("player").fetchCount)
|
||||
.tracking {
|
||||
try Table("player").fetchCount($0)
|
||||
}
|
||||
.print(to: log)
|
||||
.shared(
|
||||
in: dbQueue,
|
||||
@@ -205,7 +213,9 @@ class SharedValueObservationTests: GRDBTestCase {
|
||||
|
||||
let log = Log()
|
||||
var sharedObservation: SharedValueObservation<Int>? = ValueObservation
|
||||
.tracking(Table("player").fetchCount)
|
||||
.tracking {
|
||||
try Table("player").fetchCount($0)
|
||||
}
|
||||
.print(to: log)
|
||||
.shared(
|
||||
in: dbQueue,
|
||||
@@ -251,7 +261,9 @@ class SharedValueObservationTests: GRDBTestCase {
|
||||
|
||||
let log = Log()
|
||||
var sharedObservation: SharedValueObservation<Int>? = ValueObservation
|
||||
.tracking(Table("player").fetchCount)
|
||||
.tracking {
|
||||
try Table("player").fetchCount($0)
|
||||
}
|
||||
.print(to: log)
|
||||
.shared(
|
||||
in: dbQueue,
|
||||
@@ -345,7 +357,9 @@ class SharedValueObservationTests: GRDBTestCase {
|
||||
|
||||
let log = Log()
|
||||
@Mutex var sharedObservation: SharedValueObservation<Int>? = ValueObservation
|
||||
.tracking(Table("player").fetchCount)
|
||||
.tracking {
|
||||
try Table("player").fetchCount($0)
|
||||
}
|
||||
.print(to: log)
|
||||
.shared(
|
||||
in: dbQueue,
|
||||
@@ -398,7 +412,9 @@ class SharedValueObservationTests: GRDBTestCase {
|
||||
}
|
||||
|
||||
let publisher = ValueObservation
|
||||
.tracking(Table("player").fetchCount)
|
||||
.tracking {
|
||||
try Table("player").fetchCount($0)
|
||||
}
|
||||
.shared(in: dbQueue) // default async
|
||||
.publisher()
|
||||
|
||||
@@ -430,7 +446,9 @@ class SharedValueObservationTests: GRDBTestCase {
|
||||
|
||||
let log = Log()
|
||||
var sharedObservation: SharedValueObservation<Int>? = ValueObservation
|
||||
.tracking(Table("player").fetchCount)
|
||||
.tracking {
|
||||
try Table("player").fetchCount($0)
|
||||
}
|
||||
.print(to: log)
|
||||
.shared(
|
||||
in: dbQueue,
|
||||
@@ -640,7 +658,9 @@ class SharedValueObservationTests: GRDBTestCase {
|
||||
}
|
||||
|
||||
let values = ValueObservation
|
||||
.tracking(Table("player").fetchCount)
|
||||
.tracking {
|
||||
try Table("player").fetchCount($0)
|
||||
}
|
||||
.shared(in: dbQueue)
|
||||
.values()
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ class ValueObservationCountTests: GRDBTestCase {
|
||||
struct T: TableRecord { }
|
||||
|
||||
try assertValueObservation(
|
||||
ValueObservation.trackingConstantRegion(T.fetchCount),
|
||||
ValueObservation.trackingConstantRegion { try T.fetchCount($0) },
|
||||
records: [0, 1, 1, 2, 3, 4],
|
||||
setup: { db in
|
||||
try db.execute(sql: "CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT)")
|
||||
@@ -29,7 +29,9 @@ class ValueObservationCountTests: GRDBTestCase {
|
||||
struct T: TableRecord { }
|
||||
|
||||
try assertValueObservation(
|
||||
ValueObservation.trackingConstantRegion(T.fetchCount).removeDuplicates(),
|
||||
ValueObservation
|
||||
.trackingConstantRegion { try T.fetchCount($0) }
|
||||
.removeDuplicates(),
|
||||
records: [0, 1, 2, 3, 4],
|
||||
setup: { db in
|
||||
try db.execute(sql: "CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT)")
|
||||
|
||||
@@ -21,7 +21,7 @@ class ValueObservationDatabaseValueConvertibleTests: GRDBTestCase {
|
||||
let request = SQLRequest<Name>(sql: "SELECT name FROM t ORDER BY id")
|
||||
|
||||
try assertValueObservation(
|
||||
ValueObservation.trackingConstantRegion(request.fetchAll),
|
||||
ValueObservation.trackingConstantRegion { try request.fetchAll($0) },
|
||||
records: [
|
||||
[],
|
||||
[Name(rawValue: "foo")],
|
||||
@@ -44,7 +44,9 @@ class ValueObservationDatabaseValueConvertibleTests: GRDBTestCase {
|
||||
})
|
||||
|
||||
try assertValueObservation(
|
||||
ValueObservation.trackingConstantRegion(request.fetchAll).removeDuplicates(),
|
||||
ValueObservation
|
||||
.trackingConstantRegion { try request.fetchAll($0) }
|
||||
.removeDuplicates(),
|
||||
records: [
|
||||
[],
|
||||
[Name(rawValue: "foo")],
|
||||
@@ -70,7 +72,7 @@ class ValueObservationDatabaseValueConvertibleTests: GRDBTestCase {
|
||||
let request = SQLRequest<Name>(sql: "SELECT name FROM t ORDER BY id DESC")
|
||||
|
||||
try assertValueObservation(
|
||||
ValueObservation.trackingConstantRegion(request.fetchOne),
|
||||
ValueObservation.trackingConstantRegion { try request.fetchOne($0) },
|
||||
records: [
|
||||
nil,
|
||||
Name(rawValue: "foo"),
|
||||
@@ -103,7 +105,9 @@ class ValueObservationDatabaseValueConvertibleTests: GRDBTestCase {
|
||||
})
|
||||
|
||||
try assertValueObservation(
|
||||
ValueObservation.trackingConstantRegion(request.fetchOne).removeDuplicates(),
|
||||
ValueObservation
|
||||
.trackingConstantRegion { try request.fetchOne($0) }
|
||||
.removeDuplicates(),
|
||||
records: [
|
||||
nil,
|
||||
Name(rawValue: "foo"),
|
||||
@@ -137,7 +141,7 @@ class ValueObservationDatabaseValueConvertibleTests: GRDBTestCase {
|
||||
let request = SQLRequest<Name?>(sql: "SELECT name FROM t ORDER BY id")
|
||||
|
||||
try assertValueObservation(
|
||||
ValueObservation.trackingConstantRegion(request.fetchAll),
|
||||
ValueObservation.trackingConstantRegion { try request.fetchAll($0) },
|
||||
records: [
|
||||
[],
|
||||
[Name(rawValue: "foo")],
|
||||
@@ -160,7 +164,9 @@ class ValueObservationDatabaseValueConvertibleTests: GRDBTestCase {
|
||||
})
|
||||
|
||||
try assertValueObservation(
|
||||
ValueObservation.trackingConstantRegion(request.fetchAll).removeDuplicates(),
|
||||
ValueObservation
|
||||
.trackingConstantRegion { try request.fetchAll($0) }
|
||||
.removeDuplicates(),
|
||||
records: [
|
||||
[],
|
||||
[Name(rawValue: "foo")],
|
||||
@@ -186,7 +192,7 @@ class ValueObservationDatabaseValueConvertibleTests: GRDBTestCase {
|
||||
let request = SQLRequest<Name?>(sql: "SELECT name FROM t ORDER BY id DESC")
|
||||
|
||||
try assertValueObservation(
|
||||
ValueObservation.trackingConstantRegion(request.fetchOne),
|
||||
ValueObservation.trackingConstantRegion { try request.fetchOne($0) },
|
||||
records: [
|
||||
.none,
|
||||
Name(rawValue: "foo"),
|
||||
@@ -221,7 +227,9 @@ class ValueObservationDatabaseValueConvertibleTests: GRDBTestCase {
|
||||
})
|
||||
|
||||
try assertValueObservation(
|
||||
ValueObservation.trackingConstantRegion(request.fetchOne).removeDuplicates(),
|
||||
ValueObservation
|
||||
.trackingConstantRegion { try request.fetchOne($0) }
|
||||
.removeDuplicates(),
|
||||
records: [
|
||||
.none,
|
||||
Name(rawValue: "foo"),
|
||||
|
||||
@@ -196,7 +196,7 @@ class ValueObservationFetchTests: GRDBTestCase {
|
||||
func testRemoveDuplicates() throws {
|
||||
try assertValueObservation(
|
||||
ValueObservation
|
||||
.trackingConstantRegion(Table("t").fetchCount)
|
||||
.trackingConstantRegion { try Table("t").fetchCount($0) }
|
||||
.removeDuplicates(),
|
||||
records: [0, 1, 2],
|
||||
setup: { db in
|
||||
@@ -213,7 +213,7 @@ class ValueObservationFetchTests: GRDBTestCase {
|
||||
try assertValueObservation(
|
||||
ValueObservation
|
||||
.trackingConstantRegion { try Int.fetchOne($0, sql: "SELECT COUNT(*) FROM t")! }
|
||||
.removeDuplicates(by: ==),
|
||||
.removeDuplicates { $0 == $1 },
|
||||
records: [0, 1, 2],
|
||||
setup: { db in
|
||||
try db.execute(sql: "CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT)")
|
||||
|
||||
@@ -4,7 +4,7 @@ import GRDB
|
||||
class ValueObservationMapTests: GRDBTestCase {
|
||||
func testMap() throws {
|
||||
let valueObservation = ValueObservation
|
||||
.trackingConstantRegion(Table("t").fetchCount)
|
||||
.trackingConstantRegion { try Table("t").fetchCount($0) }
|
||||
.map { "\($0)" }
|
||||
|
||||
try assertValueObservation(
|
||||
|
||||
@@ -76,7 +76,7 @@ class ValueObservationQueryInterfaceRequestTests: GRDBTestCase {
|
||||
.including(all: Parent.children.orderByPrimaryKey())
|
||||
.orderByPrimaryKey()
|
||||
.asRequest(of: Row.self)
|
||||
let observation = ValueObservation.trackingConstantRegion(request.fetchOne)
|
||||
let observation = ValueObservation.trackingConstantRegion { try request.fetchOne($0) }
|
||||
|
||||
let recorder = observation.record(in: dbQueue)
|
||||
try dbQueue.writeWithoutTransaction(performDatabaseModifications)
|
||||
@@ -113,7 +113,7 @@ class ValueObservationQueryInterfaceRequestTests: GRDBTestCase {
|
||||
.including(all: Parent.children.orderByPrimaryKey())
|
||||
.orderByPrimaryKey()
|
||||
.asRequest(of: Row.self)
|
||||
let observation = ValueObservation.trackingConstantRegion(request.fetchAll)
|
||||
let observation = ValueObservation.trackingConstantRegion { try request.fetchAll($0) }
|
||||
|
||||
let recorder = observation.record(in: dbQueue)
|
||||
try dbQueue.writeWithoutTransaction(performDatabaseModifications)
|
||||
@@ -171,7 +171,7 @@ class ValueObservationQueryInterfaceRequestTests: GRDBTestCase {
|
||||
.asRequest(of: ParentInfo.self)
|
||||
|
||||
try assertValueObservation(
|
||||
ValueObservation.trackingConstantRegion(request.fetchOne),
|
||||
ValueObservation.trackingConstantRegion { try request.fetchOne($0) },
|
||||
records: [
|
||||
nil,
|
||||
ParentInfo(
|
||||
@@ -240,7 +240,7 @@ class ValueObservationQueryInterfaceRequestTests: GRDBTestCase {
|
||||
.asRequest(of: ParentInfo.self)
|
||||
|
||||
try assertValueObservation(
|
||||
ValueObservation.trackingConstantRegion(request.fetchAll),
|
||||
ValueObservation.trackingConstantRegion { try request.fetchAll($0) },
|
||||
records: [
|
||||
[],
|
||||
[
|
||||
|
||||
@@ -18,7 +18,7 @@ class ValueObservationRecordTests: GRDBTestCase {
|
||||
let request = SQLRequest<Player>(sql: "SELECT * FROM t ORDER BY id")
|
||||
|
||||
try assertValueObservation(
|
||||
ValueObservation.trackingConstantRegion(request.fetchAll),
|
||||
ValueObservation.trackingConstantRegion { try request.fetchAll($0) },
|
||||
records: [
|
||||
[],
|
||||
[Player(id: 1, name: "foo")],
|
||||
@@ -71,7 +71,7 @@ class ValueObservationRecordTests: GRDBTestCase {
|
||||
let request = SQLRequest<Player>(sql: "SELECT * FROM t ORDER BY id DESC")
|
||||
|
||||
try assertValueObservation(
|
||||
ValueObservation.trackingConstantRegion(request.fetchOne),
|
||||
ValueObservation.trackingConstantRegion { try request.fetchOne($0) },
|
||||
records: [
|
||||
nil,
|
||||
Player(id: 1, name: "foo"),
|
||||
|
||||
@@ -6,7 +6,7 @@ class ValueObservationRowTests: GRDBTestCase {
|
||||
let request = SQLRequest<Row>(sql: "SELECT * FROM t ORDER BY id")
|
||||
|
||||
try assertValueObservation(
|
||||
ValueObservation.trackingConstantRegion(request.fetchAll),
|
||||
ValueObservation.trackingConstantRegion { try request.fetchAll($0) },
|
||||
records: [
|
||||
[],
|
||||
[["id":1, "name":"foo"]],
|
||||
@@ -29,7 +29,9 @@ class ValueObservationRowTests: GRDBTestCase {
|
||||
})
|
||||
|
||||
try assertValueObservation(
|
||||
ValueObservation.trackingConstantRegion(request.fetchAll).removeDuplicates(),
|
||||
ValueObservation
|
||||
.trackingConstantRegion { try request.fetchAll($0) }
|
||||
.removeDuplicates(),
|
||||
records: [
|
||||
[],
|
||||
[["id":1, "name":"foo"]],
|
||||
@@ -55,7 +57,7 @@ class ValueObservationRowTests: GRDBTestCase {
|
||||
let request = SQLRequest<Row>(sql: "SELECT * FROM t ORDER BY id DESC")
|
||||
|
||||
try assertValueObservation(
|
||||
ValueObservation.trackingConstantRegion(request.fetchOne),
|
||||
ValueObservation.trackingConstantRegion { try request.fetchOne($0) },
|
||||
records: [
|
||||
nil,
|
||||
["id":1, "name":"foo"],
|
||||
@@ -80,7 +82,9 @@ class ValueObservationRowTests: GRDBTestCase {
|
||||
})
|
||||
|
||||
try assertValueObservation(
|
||||
ValueObservation.trackingConstantRegion(request.fetchOne).removeDuplicates(),
|
||||
ValueObservation
|
||||
.trackingConstantRegion { try request.fetchOne($0) }
|
||||
.removeDuplicates(),
|
||||
records: [
|
||||
nil,
|
||||
["id":1, "name":"foo"],
|
||||
@@ -106,7 +110,9 @@ class ValueObservationRowTests: GRDBTestCase {
|
||||
|
||||
func testFTS4Observation() throws {
|
||||
try assertValueObservation(
|
||||
ValueObservation.trackingConstantRegion(SQLRequest<Row>(sql: "SELECT * FROM ft_documents").fetchAll),
|
||||
ValueObservation.trackingConstantRegion {
|
||||
try SQLRequest<Row>(sql: "SELECT * FROM ft_documents").fetchAll($0)
|
||||
},
|
||||
records: [
|
||||
[],
|
||||
[["content":"foo"]]],
|
||||
@@ -120,7 +126,9 @@ class ValueObservationRowTests: GRDBTestCase {
|
||||
|
||||
func testSynchronizedFTS4Observation() throws {
|
||||
try assertValueObservation(
|
||||
ValueObservation.trackingConstantRegion(SQLRequest<Row>(sql: "SELECT * FROM ft_documents").fetchAll),
|
||||
ValueObservation.trackingConstantRegion {
|
||||
try SQLRequest<Row>(sql: "SELECT * FROM ft_documents").fetchAll($0)
|
||||
},
|
||||
records: [
|
||||
[],
|
||||
[["content":"foo"]]],
|
||||
@@ -141,11 +149,13 @@ class ValueObservationRowTests: GRDBTestCase {
|
||||
|
||||
func testJoinedFTS4Observation() throws {
|
||||
try assertValueObservation(
|
||||
ValueObservation.trackingConstantRegion(SQLRequest<Row>(sql: """
|
||||
SELECT document.* FROM document
|
||||
JOIN ft_document ON ft_document.rowid = document.id
|
||||
WHERE ft_document MATCH 'foo'
|
||||
""").fetchAll),
|
||||
ValueObservation.trackingConstantRegion {
|
||||
try SQLRequest<Row>(sql: """
|
||||
SELECT document.* FROM document
|
||||
JOIN ft_document ON ft_document.rowid = document.id
|
||||
WHERE ft_document MATCH 'foo'
|
||||
""").fetchAll($0)
|
||||
},
|
||||
records: [
|
||||
[],
|
||||
[["id":1]]],
|
||||
|
||||
@@ -101,7 +101,7 @@ class ValueObservationTests: GRDBTestCase {
|
||||
@Mutex var region: DatabaseRegion?
|
||||
let expectation = self.expectation(description: "")
|
||||
let observation = ValueObservation
|
||||
.trackingConstantRegion(request.fetchAll)
|
||||
.trackingConstantRegion { try request.fetchAll($0) }
|
||||
.handleEvents(willTrackRegion: { region in
|
||||
$region.withLock { $0 = region }
|
||||
expectation.fulfill()
|
||||
@@ -134,7 +134,7 @@ class ValueObservationTests: GRDBTestCase {
|
||||
@Mutex var region: DatabaseRegion?
|
||||
let expectation = self.expectation(description: "")
|
||||
let observation = ValueObservation
|
||||
.trackingConstantRegion(request.fetchAll)
|
||||
.trackingConstantRegion { try request.fetchAll($0) }
|
||||
.handleEvents(willTrackRegion: { region in
|
||||
$region.withLock { $0 = region }
|
||||
expectation.fulfill()
|
||||
@@ -163,7 +163,9 @@ class ValueObservationTests: GRDBTestCase {
|
||||
do {
|
||||
try assertValueObservation(
|
||||
ValueObservation
|
||||
.tracking(region: DatabaseRegion.fullDatabase, fetch: Table("t").fetchCount),
|
||||
.tracking(
|
||||
region: DatabaseRegion.fullDatabase,
|
||||
fetch: { try Table("t").fetchCount($0) }),
|
||||
records: [0, 1, 1, 2, 3, 4],
|
||||
setup: { db in
|
||||
try db.execute(sql: """
|
||||
@@ -197,7 +199,7 @@ class ValueObservationTests: GRDBTestCase {
|
||||
let logger = TestStream()
|
||||
let observation = ValueObservation.tracking(
|
||||
region: Table("t"),
|
||||
fetch: Table("t").fetchCount)
|
||||
fetch: { try Table("t").fetchCount($0) })
|
||||
.print(to: logger)
|
||||
|
||||
let expectation = self.expectation(description: "")
|
||||
@@ -241,7 +243,7 @@ class ValueObservationTests: GRDBTestCase {
|
||||
let logger = TestStream()
|
||||
let observation = ValueObservation.tracking(
|
||||
region: Table("other"),
|
||||
fetch: Table("t").fetchCount)
|
||||
fetch: { try Table("t").fetchCount($0) })
|
||||
.print(to: logger)
|
||||
|
||||
let expectation = self.expectation(description: "")
|
||||
@@ -285,7 +287,7 @@ class ValueObservationTests: GRDBTestCase {
|
||||
let logger = TestStream()
|
||||
let observation = ValueObservation.tracking(
|
||||
region: Table("t"), Table("other"),
|
||||
fetch: Table("t").fetchCount)
|
||||
fetch: { try Table("t").fetchCount($0) })
|
||||
.print(to: logger)
|
||||
|
||||
let expectation = self.expectation(description: "")
|
||||
@@ -812,7 +814,7 @@ class ValueObservationTests: GRDBTestCase {
|
||||
// Observe N times
|
||||
let cancellables = (0..<N).map { _ in
|
||||
ValueObservation
|
||||
.tracking(Table("t").fetchCount)
|
||||
.tracking { try Table("t").fetchCount($0) }
|
||||
.removeDuplicates()
|
||||
.start(
|
||||
in: dbWriter,
|
||||
@@ -853,7 +855,7 @@ class ValueObservationTests: GRDBTestCase {
|
||||
let task = Task { () -> [Int] in
|
||||
var counts: [Int] = []
|
||||
let observation = ValueObservation
|
||||
.trackingConstantRegion(Table("t").fetchCount)
|
||||
.trackingConstantRegion { try Table("t").fetchCount($0) }
|
||||
.handleEvents(didCancel: { cancellationExpectation.fulfill() })
|
||||
|
||||
for try await count in try observation.values(in: writer).prefix(while: { $0 <= 3 }) {
|
||||
@@ -887,7 +889,7 @@ class ValueObservationTests: GRDBTestCase {
|
||||
let task = Task { @MainActor () -> [Int] in
|
||||
var counts: [Int] = []
|
||||
let observation = ValueObservation
|
||||
.trackingConstantRegion(Table("t").fetchCount)
|
||||
.trackingConstantRegion { try Table("t").fetchCount($0) }
|
||||
.handleEvents(didCancel: { cancellationExpectation.fulfill() })
|
||||
|
||||
#warning("TODO: check the relevance of this test, now that scheduling is no longer supported")
|
||||
@@ -922,7 +924,7 @@ class ValueObservationTests: GRDBTestCase {
|
||||
let task = Task { () -> [Int] in
|
||||
var counts: [Int] = []
|
||||
let observation = ValueObservation
|
||||
.trackingConstantRegion(Table("t").fetchCount)
|
||||
.trackingConstantRegion { try Table("t").fetchCount($0) }
|
||||
.handleEvents(didCancel: { cancellationExpectation.fulfill() })
|
||||
|
||||
for try await count in observation.values(in: writer) {
|
||||
@@ -961,7 +963,7 @@ class ValueObservationTests: GRDBTestCase {
|
||||
let task = Task { @MainActor () -> [Int] in
|
||||
var counts: [Int] = []
|
||||
let observation = ValueObservation
|
||||
.trackingConstantRegion(Table("t").fetchCount)
|
||||
.trackingConstantRegion { try Table("t").fetchCount($0) }
|
||||
.handleEvents(didCancel: { cancellationExpectation.fulfill() })
|
||||
|
||||
#warning("TODO: check the relevance of this test, now that scheduling is no longer supported")
|
||||
@@ -997,7 +999,7 @@ class ValueObservationTests: GRDBTestCase {
|
||||
// Launch a task that we'll cancel
|
||||
let cancelledTask = Task<String, Error> {
|
||||
// Loops until cancelled
|
||||
let observation = ValueObservation.trackingConstantRegion(Table("t").fetchCount)
|
||||
let observation = ValueObservation.trackingConstantRegion { try Table("t").fetchCount($0) }
|
||||
let cancelledObservation = observation.handleEvents(didCancel: {
|
||||
cancellationExpectation.fulfill()
|
||||
})
|
||||
@@ -1007,7 +1009,7 @@ class ValueObservationTests: GRDBTestCase {
|
||||
|
||||
// Lanch the task that cancels
|
||||
Task {
|
||||
let observation = ValueObservation.trackingConstantRegion(Table("t").fetchCount)
|
||||
let observation = ValueObservation.trackingConstantRegion { try Table("t").fetchCount($0) }
|
||||
for try await count in observation.values(in: writer) {
|
||||
if count >= 3 {
|
||||
cancelledTask.cancel()
|
||||
@@ -1104,7 +1106,7 @@ class ValueObservationTests: GRDBTestCase {
|
||||
try $0.execute(sql: "CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT)")
|
||||
}
|
||||
let observation = ValueObservation.tracking {
|
||||
return try Table("t").fetchCount($0)
|
||||
try Table("t").fetchCount($0)
|
||||
}
|
||||
|
||||
let initialValueExpectation = self.expectation(description: "")
|
||||
@@ -1169,7 +1171,7 @@ class ValueObservationTests: GRDBTestCase {
|
||||
// transaction observer.
|
||||
let installedExpectation = expectation(description: "transaction observer installed")
|
||||
let finalExpectation = expectation(description: "final value")
|
||||
let initialObservation = ValueObservation.trackingConstantRegion(Table("s").fetchCount)
|
||||
let initialObservation = ValueObservation.trackingConstantRegion { try Table("s").fetchCount($0) }
|
||||
let cancellable = initialObservation.start(
|
||||
in: writer,
|
||||
// Immediate initial value so that the next value comes
|
||||
@@ -1201,7 +1203,7 @@ class ValueObservationTests: GRDBTestCase {
|
||||
|
||||
// Start as many observations as there are readers
|
||||
for _ in 0..<writer.configuration.maximumReaderCount {
|
||||
let observation = ValueObservation.trackingConstantRegion(Table("s").fetchCount)
|
||||
let observation = ValueObservation.trackingConstantRegion { try Table("s").fetchCount($0) }
|
||||
let cancellable = observation.start(
|
||||
in: writer,
|
||||
onError: { error in XCTFail("Unexpected error: \(error)") },
|
||||
@@ -1238,7 +1240,7 @@ class ValueObservationTests: GRDBTestCase {
|
||||
|
||||
do {
|
||||
let dbPool = try makeDatabasePool(filename: "test")
|
||||
let observation = ValueObservation.tracking(Table("t").fetchCount)
|
||||
let observation = ValueObservation.tracking { try Table("t").fetchCount($0) }
|
||||
_ = observation.start(
|
||||
in: dbPool, scheduling: .immediate,
|
||||
onError: { error in
|
||||
@@ -1262,7 +1264,7 @@ class ValueObservationTests: GRDBTestCase {
|
||||
|
||||
do {
|
||||
let dbPool = try makeDatabasePool(filename: "test")
|
||||
let observation = ValueObservation.tracking(Table("t").fetchCount)
|
||||
let observation = ValueObservation.tracking { try Table("t").fetchCount($0) }
|
||||
let expectation = self.expectation(description: "completion")
|
||||
expectation.assertForOverFulfill = false
|
||||
let cancellable = observation.start(
|
||||
@@ -1288,7 +1290,7 @@ class ValueObservationTests: GRDBTestCase {
|
||||
try? FileManager.default.removeItem(at: url.deletingLastPathComponent().appendingPathComponent("Issue1383.sqlite-shm"))
|
||||
|
||||
let dbPool = try DatabasePool(path: url.path)
|
||||
let observation = ValueObservation.tracking(Table("t").fetchCount)
|
||||
let observation = ValueObservation.tracking { try Table("t").fetchCount($0) }
|
||||
_ = observation.start(
|
||||
in: dbPool, scheduling: .immediate,
|
||||
onError: { error in
|
||||
|
||||
Reference in new issue
Block a user