diff --git a/Package.resolved b/Package.resolved index a192e0c6..cc9b932b 100644 --- a/Package.resolved +++ b/Package.resolved @@ -1,5 +1,5 @@ { - "originHash" : "2b95f254bb904411c5a0aba0e0402c157014542e9bd40eb5848c42c8598b80a9", + "originHash" : "1464a33ec5d6d5bf475cc815fedb831aec3a52c5f5d911bd6ccdf4b14db73807", "pins" : [ { "identity" : "combine-schedulers", diff --git a/Package.swift b/Package.swift index e1f278e8..e42498da 100644 --- a/Package.swift +++ b/Package.swift @@ -1,5 +1,4 @@ // swift-tools-version: 6.1 - import PackageDescription let package = Package( @@ -21,14 +20,31 @@ let package = Package( ), ], traits: [ + .default(enabledTraits: ["GRDB"]), + .trait( + name: "GRDB", + description: "Use the standard GRDB package." + ), .trait( name: "SQLiteDataTagged", description: "Introduce SQLiteData conformances to the swift-tagged package." + ), + .trait( + name: "GRDBCIPHER", + description: "Use the SQLCipher-backed GRDB package." ) ], dependencies: [ .package(url: "https://github.com/apple/swift-collections", from: "1.0.0"), .package(url: "https://github.com/groue/GRDB.swift", from: "7.6.0"), + .package( + url: "https://github.com/swift-everywhere/grdb-sqlcipher.git", + from: "7.5.0", + traits: [ + .trait(name: "GRDBCIPHER", condition: .when(traits: ["GRDBCIPHER"])) + ] + ), + .package(url: "https://github.com/skiptools/swift-sqlcipher.git", from: "1.3.0"), .package(url: "https://github.com/pointfreeco/swift-concurrency-extras", from: "1.0.0"), .package(url: "https://github.com/pointfreeco/swift-custom-dump", from: "1.3.3"), .package(url: "https://github.com/pointfreeco/swift-dependencies", from: "1.9.0"), @@ -51,11 +67,25 @@ let package = Package( dependencies: [ .product(name: "ConcurrencyExtras", package: "swift-concurrency-extras"), .product(name: "Dependencies", package: "swift-dependencies"), - .product(name: "GRDB", package: "GRDB.swift"), + .product( + name: "GRDB", + package: "GRDB.swift", + condition: .when(traits: ["GRDB"]) + ), + .product( + name: "GRDB", + package: "grdb-sqlcipher", + condition: .when(traits: ["GRDBCIPHER"]) + ), .product(name: "IssueReporting", package: "xctest-dynamic-overlay"), .product(name: "OrderedCollections", package: "swift-collections"), .product(name: "Perception", package: "swift-perception"), .product(name: "Sharing", package: "swift-sharing"), + .product( + name: "SQLCipher", + package: "swift-sqlcipher", + condition: .when(traits: ["GRDBCIPHER"]) + ), .product(name: "StructuredQueriesSQLite", package: "swift-structured-queries"), .product( name: "Tagged", diff --git a/Sources/SQLiteData/CloudKit/Internal/UserDatabase.swift b/Sources/SQLiteData/CloudKit/Internal/UserDatabase.swift index b0fb5edc..5f0f2f13 100644 --- a/Sources/SQLiteData/CloudKit/Internal/UserDatabase.swift +++ b/Sources/SQLiteData/CloudKit/Internal/UserDatabase.swift @@ -16,7 +16,7 @@ } package func write( - _ updates: @Sendable (Database) throws -> T + _ updates: @escaping @Sendable (Database) throws -> T ) async throws -> T { try await database.write { db in try $_isSynchronizingChanges.withValue(true) { @@ -26,7 +26,7 @@ } package func read( - _ updates: @Sendable (Database) throws -> T + _ updates: @escaping @Sendable (Database) throws -> T ) async throws -> T { try await database.read { db in try updates(db) diff --git a/Sources/SQLiteData/CloudKit/SyncEngine.swift b/Sources/SQLiteData/CloudKit/SyncEngine.swift index 871c7999..871955be 100644 --- a/Sources/SQLiteData/CloudKit/SyncEngine.swift +++ b/Sources/SQLiteData/CloudKit/SyncEngine.swift @@ -756,7 +756,7 @@ try tearDownSyncEngine() await withErrorReporting(.sqliteDataCloudKitFailure) { try await userDatabase.write { db in - for table in tables { + for table in self.tables { func open(_: some SynchronizableTable) { withErrorReporting(.sqliteDataCloudKitFailure) { try T.delete().execute(db) @@ -764,7 +764,7 @@ } open(table) } - try setUpSyncEngine(writableDB: db) + try self.setUpSyncEngine(writableDB: db) } } try await start() @@ -1591,7 +1591,7 @@ if let share = record as? CKShare { shares.append(.share(share)) } else { - upsertFromServerRecord(record, db: db) + self.upsertFromServerRecord(record, db: db) if let shareReference = record.share { shares.append(.reference(shareReference)) } @@ -1893,7 +1893,7 @@ ) async { await withErrorReporting(.sqliteDataCloudKitFailure) { try await userDatabase.write { db in - upsertFromServerRecord(serverRecord, force: force, db: db) + self.upsertFromServerRecord(serverRecord, force: force, db: db) } } } diff --git a/Sources/SQLiteData/StructuredQueries+GRDB/CustomFunctions.swift b/Sources/SQLiteData/StructuredQueries+GRDB/CustomFunctions.swift index b9defb55..18b03440 100644 --- a/Sources/SQLiteData/StructuredQueries+GRDB/CustomFunctions.swift +++ b/Sources/SQLiteData/StructuredQueries+GRDB/CustomFunctions.swift @@ -1,5 +1,9 @@ import Foundation +#if GRDBCIPHER +import SQLCipher +#else import GRDBSQLite +#endif extension Database { /// Adds a user-defined scalar `@DatabaseFunction` to a connection. diff --git a/Sources/SQLiteData/StructuredQueries+GRDB/QueryCursor.swift b/Sources/SQLiteData/StructuredQueries+GRDB/QueryCursor.swift index 286135e8..30ed9103 100644 --- a/Sources/SQLiteData/StructuredQueries+GRDB/QueryCursor.swift +++ b/Sources/SQLiteData/StructuredQueries+GRDB/QueryCursor.swift @@ -1,6 +1,10 @@ import Foundation import GRDB +#if GRDBCIPHER +import SQLCipher +#else import GRDBSQLite +#endif import StructuredQueriesCore /// A cursor of a structured query. diff --git a/Sources/SQLiteData/StructuredQueries+GRDB/SQLiteFunctionDecoder.swift b/Sources/SQLiteData/StructuredQueries+GRDB/SQLiteFunctionDecoder.swift index fc96760e..d45ddd63 100644 --- a/Sources/SQLiteData/StructuredQueries+GRDB/SQLiteFunctionDecoder.swift +++ b/Sources/SQLiteData/StructuredQueries+GRDB/SQLiteFunctionDecoder.swift @@ -1,5 +1,9 @@ import Foundation +#if GRDBCIPHER +import SQLCipher +#else import GRDBSQLite +#endif import StructuredQueriesCore @usableFromInline diff --git a/Sources/SQLiteData/StructuredQueries+GRDB/SQLiteQueryDecoder.swift b/Sources/SQLiteData/StructuredQueries+GRDB/SQLiteQueryDecoder.swift index 4aed866e..7245910d 100644 --- a/Sources/SQLiteData/StructuredQueries+GRDB/SQLiteQueryDecoder.swift +++ b/Sources/SQLiteData/StructuredQueries+GRDB/SQLiteQueryDecoder.swift @@ -1,5 +1,9 @@ import Foundation +#if GRDBCIPHER +import SQLCipher +#else import GRDBSQLite +#endif import StructuredQueriesCore @usableFromInline