mirror of
https://github.com/groue/GRDB.swift
synced 2026-12-04 05:08:44 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c4d52acc03 | ||
|
|
8deac6bf11 | ||
|
|
a4d844a92c | ||
|
|
2c11a16858 | ||
|
|
7950f797ef | ||
|
|
46fe1b58a4 |
No files matched your search
@@ -21,9 +21,6 @@
|
||||
/// This is a vendored copy of the `Disconnected` type of the Synchronization
|
||||
/// module, introduced by SE-0538:
|
||||
/// <https://github.com/swiftlang/swift-evolution/blob/main/proposals/0538-disconnected.md>
|
||||
///
|
||||
/// TODO: Remove this copy, and use the Synchronization type, when the
|
||||
/// minimum Swift version is 6.5.
|
||||
struct Disconnected<Value: ~Copyable>: ~Copyable, Sendable {
|
||||
// This is safe since the only values assigned are sent into `Disconnected`.
|
||||
nonisolated(unsafe) var _value: Value
|
||||
|
||||
@@ -10,6 +10,23 @@ private class NonSendable {
|
||||
}
|
||||
}
|
||||
|
||||
private class NonSendableRecord:
|
||||
Codable, Identifiable,
|
||||
FetchableRecord, PersistableRecord
|
||||
{
|
||||
var id: Int64
|
||||
|
||||
init(id: Int64) {
|
||||
self.id = id
|
||||
}
|
||||
|
||||
static func createTable(_ db: Database) throws {
|
||||
try db.create(table: databaseTableName) { t in
|
||||
t.autoIncrementedPrimaryKey("id")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Database readers and writers
|
||||
|
||||
/// The kinds of database readers whose async methods are tested.
|
||||
@@ -38,21 +55,25 @@ private func withTemporaryDirectory(
|
||||
|
||||
private func withDatabaseReader(
|
||||
_ kind: ReaderKind,
|
||||
_ body: (any DatabaseReader) async throws -> Void
|
||||
setup: (any DatabaseWriter) async throws -> Void = { _ in },
|
||||
test: (any DatabaseReader) async throws -> Void
|
||||
) async throws {
|
||||
switch kind {
|
||||
case .queue:
|
||||
try await body(DatabaseQueue())
|
||||
let dbQueue = try DatabaseQueue()
|
||||
try await setup(dbQueue)
|
||||
try await test(dbQueue)
|
||||
case .pool, .snapshot, .snapshotPool:
|
||||
try await withTemporaryDirectory { directoryURL in
|
||||
let dbPool = try DatabasePool(path: directoryURL.appending(path: "db.sqlite").path)
|
||||
try await setup(dbPool)
|
||||
switch kind {
|
||||
case .pool:
|
||||
try await body(dbPool)
|
||||
try await test(dbPool)
|
||||
case .snapshot:
|
||||
try await body(dbPool.makeSnapshot())
|
||||
try await test(dbPool.makeSnapshot())
|
||||
case .snapshotPool:
|
||||
try await body(dbPool.makeSnapshotPool())
|
||||
try await test(dbPool.makeSnapshotPool())
|
||||
case .queue:
|
||||
fatalError()
|
||||
}
|
||||
@@ -211,3 +232,22 @@ private func withDatabaseWriter(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Non-Sendable record results
|
||||
|
||||
@Suite struct NonSendableRecordResultTests {
|
||||
@Test(arguments: ReaderKind.allCases)
|
||||
func non_sendable_record_returned_from_read(kind: ReaderKind) async throws {
|
||||
try await withDatabaseReader(kind) { writer in
|
||||
try await writer.write { db in
|
||||
try NonSendableRecord.createTable(db)
|
||||
try NonSendableRecord(id: 1).insert(db)
|
||||
}
|
||||
} test: { reader in
|
||||
let record = try await reader.read { db in
|
||||
try NonSendableRecord.find(db, id: 1)
|
||||
}
|
||||
#expect(record.id == 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user