diff --git a/Examples/Examples.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Examples/Examples.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 6d103b31..587d0c8d 100644 --- a/Examples/Examples.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/Examples/Examples.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -1,5 +1,5 @@ { - "originHash" : "72bc7483118f950b5981c86ad1ea986d789ceef2694a317cea1b9dfff3119f82", + "originHash" : "41e7781e6c506773b6af84af513bcd6d3b1be59d635e6c4c4bd89638368e4629", "pins" : [ { "identity" : "combine-schedulers", @@ -141,8 +141,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/pointfreeco/swift-structured-queries", "state" : { - "revision" : "edb84b339542b018477bab1d8e4cca851d5fa93c", - "version" : "0.23.0" + "revision" : "3a95b70a81b7027b8a5117e7dd08188837e5f54e", + "version" : "0.24.0" } }, { diff --git a/Sources/SQLiteData/CloudKit/SyncEngine.swift b/Sources/SQLiteData/CloudKit/SyncEngine.swift index 35dda656..438e715d 100644 --- a/Sources/SQLiteData/CloudKit/SyncEngine.swift +++ b/Sources/SQLiteData/CloudKit/SyncEngine.swift @@ -311,9 +311,23 @@ .select(\.file) .fetchOne(db) if let attachedMetadatabasePath { - let attachedMetadatabaseName = URL(filePath: metadatabase.path).lastPathComponent - let metadatabaseName = URL(filePath: attachedMetadatabasePath).lastPathComponent - if attachedMetadatabaseName != metadatabaseName { + let metadatabaseName = + metadatabase.path.isEmpty + ? try URL.metadatabase( + databasePath: "", + containerIdentifier: self.container.containerIdentifier + ) + .lastPathComponent + : URL(filePath: metadatabase.path).lastPathComponent + let attachedMetadatabaseName = + URL(string: attachedMetadatabasePath)?.lastPathComponent ?? "" + + try URL.metadatabase( + databasePath: attachedMetadatabasePath, + containerIdentifier: self.container.containerIdentifier + ) + .lastPathComponent + if metadatabaseName != attachedMetadatabaseName { throw SchemaError( reason: .metadatabaseMismatch( attachedPath: attachedMetadatabasePath, @@ -1917,6 +1931,7 @@ databasePath: String, containerIdentifier: String? ) throws -> URL { + let databasePath = databasePath.isEmpty ? ":memory:" : databasePath guard let databaseURL = URL(string: databasePath) else { struct InvalidDatabasePath: Error {} @@ -1927,9 +1942,9 @@ return URL(string: "file:\(String.sqliteDataCloudKitSchemaName)?mode=memory&cache=shared")! } return - databaseURL - .deletingLastPathComponent() - .appending(component: ".\(databaseURL.deletingPathExtension().lastPathComponent)") + databaseURL.deletingLastPathComponent().appending( + component: ".\(databaseURL.deletingPathExtension().lastPathComponent)" + ) .appendingPathExtension("metadata\(containerIdentifier.map { "-\($0)" } ?? "").sqlite") } @@ -2022,12 +2037,16 @@ databasePath: databasePath, containerIdentifier: containerIdentifier ) - let path = url.path(percentEncoded: false) + let path = url.isInMemory ? url.absoluteString : url.path(percentEncoded: false) try FileManager.default.createDirectory( at: .applicationSupportDirectory, withIntermediateDirectories: true ) - _ = try DatabasePool(path: path).write { db in + let database: any DatabaseWriter = + url.isInMemory + ? try DatabaseQueue(path: path) + : try DatabasePool(path: path) + _ = try database.write { db in try #sql("SELECT 1").execute(db) } try #sql( @@ -2044,7 +2063,6 @@ package struct SchemaError: LocalizedError { package enum Reason { case cycleDetected - case inMemoryDatabase case invalidForeignKey(ForeignKey) case invalidForeignKeyAction(ForeignKey) case invalidTableName(String)