Skip to content

Commit 9e3aa61

Browse files
committed
chore: update package
1 parent 609c4d8 commit 9e3aa61

File tree

5 files changed

+34
-40
lines changed

5 files changed

+34
-40
lines changed

CHANGELOG.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,22 @@
22

33
## 1.0.0-Beta.6
44

5-
* Allow `execute` to be handled
65
* BREAKING CHANGE: `watch` queries are now throwable and therefore will need to be accompanied by a `try` e.g.
76

87
```swift
98
try database.watch()
109
```
1110

11+
* BREAKING CHANGE: `transaction` functions are now throwable and therefore will need to be accompanied by a `try` e.g.
12+
13+
```swift
14+
try await database.writeTransaction { transaction in
15+
try transaction.execute(...)
16+
}
17+
```
18+
* Allow `execute` errors to be handled
19+
* `userId` is now set to `nil` by default and therefore it is no longer required to be set to `nil` when instantiating `PowerSyncCredentials` and can therefore be left out.
20+
1221
## 1.0.0-Beta.5
1322

1423
* Implement improvements to errors originating in Kotlin so that they can be handled in Swift

Demo/PowerSyncExample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.resolved

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ let package = Package(
1616
targets: ["PowerSync"]),
1717
],
1818
dependencies: [
19-
.package(url: "https://github.com/powersync-ja/powersync-kotlin.git", exact: "1.0.0-BETA22.0"),
19+
.package(url: "https://github.com/powersync-ja/powersync-kotlin.git", exact: "1.0.0-BETA23.0"),
2020
.package(url: "https://github.com/powersync-ja/powersync-sqlite-core-swift.git", "0.3.9"..<"0.4.0")
2121
],
2222
targets: [

Sources/PowerSync/Kotlin/KotlinPowerSyncDatabaseImpl.swift

Lines changed: 19 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -195,45 +195,30 @@ final class KotlinPowerSyncDatabaseImpl: PowerSyncDatabaseProtocol {
195195
}
196196

197197
public func writeTransaction<R>(callback: @escaping (any PowerSyncTransaction) throws -> R) async throws -> R {
198-
var err: Error? = nil
199-
let result = try await kotlinDatabase.writeTransaction { transaction in
200-
do {
201-
let res = try callback(transaction)
202-
return res as R
203-
} catch {
204-
err = error
205-
return TransactionResponse.rollback
206-
}
207-
}
208-
209-
if(err != nil) {
210-
throw err!
211-
}
212-
213-
return result as! R
198+
return try await kotlinDatabase.writeTransaction(callback: TransactionCallback(callback: callback)) as! R
214199
}
215200

216201
public func readTransaction<R>(callback: @escaping (any PowerSyncTransaction) throws -> R) async throws -> R {
217-
var err: Error? = nil
218-
let result = try await kotlinDatabase.readTransaction { transaction in
219-
do {
220-
let res = try callback(transaction)
221-
return res as R
222-
} catch {
223-
err = error
224-
return TransactionResponse.rollback
225-
}
226-
}
227-
228-
if(err != nil) {
229-
throw err!
230-
}
231-
232-
return result as! R
202+
return try await kotlinDatabase.readTransaction(callback: TransactionCallback(callback: callback)) as! R
233203
}
204+
}
205+
206+
class TransactionCallback<R>: PowerSyncKotlin.ThrowableTransactionCallback {
207+
let callback: (PowerSyncTransaction) throws -> R
234208

235-
public func readTransaction<R>(callback: @escaping (any PowerSyncTransaction) -> R) async throws -> R {
236-
return try await kotlinDatabase.readTransaction(callback: callback) as! R
209+
init(callback: @escaping (PowerSyncTransaction) throws -> R) {
210+
self.callback = callback
211+
}
212+
213+
func execute(transaction: PowerSyncKotlin.PowerSyncTransaction) throws -> Any{
214+
do {
215+
return try callback(transaction)
216+
} catch let error {
217+
return PowerSyncKotlin.PowerSyncException(
218+
message: error.localizedDescription,
219+
cause: PowerSyncKotlin.KotlinThrowable(message: error.localizedDescription)
220+
)
221+
}
237222
}
238223
}
239224

0 commit comments

Comments
 (0)