Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Sources/SQLiteData/CloudKit/CloudKitSharing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,9 @@
recordPrimaryKey: record.primaryKey.rawIdentifier,
reason: .recordMetadataNotFound,
debugDescription: """
No sync metadata found for record. Has the record been saved to the database?
No sync metadata found for record. Has the record been saved to the database \
and synchronized to iCloud? You can invoke 'SyncEngine.sendChanges()` to force \
synchronization.
"""
)
}
Expand Down
15 changes: 9 additions & 6 deletions Sources/SQLiteData/CloudKit/SyncEngine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
privateTables: repeat (each T2).Type,
containerIdentifier: String? = nil,
defaultZone: CKRecordZone = CKRecordZone(zoneName: "co.pointfree.SQLiteData.defaultZone"),
startImmediately: Bool = true,
startImmediately: Bool? = nil,
delegate: (any SyncEngineDelegate)? = nil,
logger: Logger = isTesting
? Logger(.disabled) : Logger(subsystem: "SQLiteData", category: "CloudKit")
Expand Down Expand Up @@ -152,7 +152,7 @@
privateTables: allPrivateTables
)
try setUpSyncEngine()
if startImmediately {
if startImmediately ?? !isTesting {
_ = try start()
}
return
Expand Down Expand Up @@ -201,7 +201,7 @@
privateTables: allPrivateTables
)
try setUpSyncEngine()
if startImmediately {
if startImmediately ?? !isTesting {
_ = try start()
}
}
Expand Down Expand Up @@ -1167,14 +1167,17 @@
}
func open<T>(_: some SynchronizableTable<T>) async -> CKRecord? {
let row =
withErrorReporting(.sqliteDataCloudKitFailure) {
try userDatabase.read { db in
try T
await withErrorReporting(.sqliteDataCloudKitFailure) {
// NB: Fake 'sending' result.
nonisolated(unsafe) var result: T.QueryOutput?
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can remove this in the future if/when GRDB adopts sending.

try await userDatabase.read { db in
result = try T
.where {
#sql("\($0.primaryKey) = \(bind: metadata.recordPrimaryKey)")
}
.fetchOne(db)
}
return result
}
?? nil
guard let row
Expand Down
Loading