Skip to content

Commit 81074db

Browse files
Update WatchOS extension loading
1 parent 4f112b2 commit 81074db

File tree

6 files changed

+20
-12
lines changed

6 files changed

+20
-12
lines changed

Demo/GRDB Demo/GRDB Demo/GRDB_DemoApp.swift

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,11 @@ func openDatabase()
3131
).first!
3232
.appendingPathComponent("test.sqlite")
3333

34-
var config = Configuration()
35-
config.configurePowerSync(
36-
schema: schema
37-
)
38-
3934
do {
35+
var config = Configuration()
36+
config.configurePowerSync(
37+
schema: schema
38+
)
4039
let grdb = try DatabasePool(
4140
path: dbUrl.path,
4241
configuration: config

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ import GRDB
9494

9595
// Configure GRDB with PowerSync support
9696
var config = Configuration()
97-
config.configurePowerSync(schema: mySchema)
97+
try config.configurePowerSync(schema: mySchema)
9898

9999
// Create database with PowerSync enabled
100100
let dbPool = try DatabasePool(

Sources/PowerSync/resolvePowerSyncLoadableExtensionPath.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@
5555
///
5656
/// - Returns: The file system path to the PowerSync SQLite extension, or `nil` on watchOS
5757
/// (where the extension is statically loaded and doesn't require a path)
58-
/// - Throws: An error if the extension path cannot be resolved on platforms that require it
58+
/// - Throws: An error if the extension path cannot be resolved on platforms that require it or
59+
/// if the extension could not be registered on watchOS.
5960
public func resolvePowerSyncLoadableExtensionPath() throws -> String? {
6061
return try kotlinResolvePowerSyncLoadableExtensionPath()
6162
}

Sources/PowerSyncGRDB/Config/Configuration+PowerSync.swift

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,25 @@ public extension Configuration {
1515
/// Example usage:
1616
/// ```swift
1717
/// var config = Configuration()
18-
/// config.configurePowerSync(schema: mySchema)
18+
/// try config.configurePowerSync(schema: mySchema)
1919
/// let dbQueue = try DatabaseQueue(path: dbPath, configuration: config)
2020
/// ```
2121
///
2222
/// - Parameter schema: The PowerSync `Schema` describing your sync views.
23+
/// - Throws: An error if the PowerSync extension path cannot be resolved,
24+
/// if extension loading cannot be enabled, or if the PowerSync extension
25+
/// fails to load or initialize.
2326
mutating func configurePowerSync(
2427
schema: Schema
25-
) {
28+
) throws {
29+
// Handles the case on WatchOS where the extension is statically loaded.
30+
// We need to register the extension before SQLite connections are established.
31+
// This should only throw on non-WatchOS platforms if the extension path cannot be resolved. So we catch and ignore the error.
32+
let extensionPath = try resolvePowerSyncLoadableExtensionPath()
33+
2634
// Register the PowerSync core extension
2735
prepareDatabase { database in
28-
guard let extensionPath = try resolvePowerSyncLoadableExtensionPath() else {
36+
guard let extensionPath = extensionPath else {
2937
// We get the extension path for non WatchOS platforms.
3038
// The Kotlin registration for automatically loading the extension does not seem to work.
3139
// We explicitly initialize the extension here.

Sources/PowerSyncGRDB/GRDBPowerSyncDatabase.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import PowerSync
2121
///
2222
/// // Configure GRDB with PowerSync support
2323
/// var config = Configuration()
24-
/// config.configurePowerSync(schema: schema)
24+
/// try config.configurePowerSync(schema: schema)
2525
///
2626
/// // Create the database pool
2727
/// let dbPool = try DatabasePool(path: "path/to/db", configuration: config)

Tests/PowerSyncGRDBTests/BasicTest.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ final class GRDBTests: XCTestCase {
5959

6060
var config = Configuration()
6161

62-
config.configurePowerSync(
62+
try config.configurePowerSync(
6363
schema: schema
6464
)
6565

0 commit comments

Comments
 (0)