Skip to content
Merged
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

## Unreleased

* Fix null values in CRUD entries being reported as strings.
* [Internal] Instantiate Kotlin Kermit logger directly.
* [Internal] Improved connection context error handling.

## 1.4.0

Expand Down
13 changes: 8 additions & 5 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let packageName = "PowerSync"

// Set this to the absolute path of your Kotlin SDK checkout if you want to use a local Kotlin
Expand Down Expand Up @@ -31,8 +32,8 @@ if let kotlinSdkPath = localKotlinSdkOverride {
// Not using a local build, so download from releases
conditionalTargets.append(.binaryTarget(
name: "PowerSyncKotlin",
url: "https://github.com/powersync-ja/powersync-kotlin/releases/download/v1.4.0/PowersyncKotlinRelease.zip",
checksum: "e800db216fc1c9722e66873deb4f925530267db6dbd5e2114dd845cc62c28cd9"
url: "https://github.com/powersync-ja/powersync-kotlin/releases/download/v1.5.0/PowersyncKotlinRelease.zip",
checksum: "cb1d717d28411aff0bfdeeaa837ae01514ebf5d64203dc565a9520a2912bae9d"
))
}

Expand All @@ -59,7 +60,8 @@ let package = Package(
// Products define the executables and libraries a package produces, making them visible to other packages.
.library(
name: packageName,
targets: ["PowerSync"]),
targets: ["PowerSync"]
)
],
dependencies: conditionalDependencies,
targets: [
Expand All @@ -70,10 +72,11 @@ let package = Package(
dependencies: [
kotlinTargetDependency,
.product(name: "PowerSyncSQLiteCore", package: corePackageName)
]),
]
),
.testTarget(
name: "PowerSyncTests",
dependencies: ["PowerSync"]
),
)
] + conditionalTargets
)
73 changes: 56 additions & 17 deletions Sources/PowerSync/Kotlin/KotlinPowerSyncDatabaseImpl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,7 @@ final class KotlinPowerSyncDatabaseImpl: PowerSyncDatabaseProtocol {
return try await wrapPowerSyncException {
try safeCast(
await kotlinDatabase.writeLock(
callback: LockCallback(
callback: callback
)
callback: wrapLockContext(callback: callback)
),
to: R.self
)
Expand All @@ -290,9 +288,7 @@ final class KotlinPowerSyncDatabaseImpl: PowerSyncDatabaseProtocol {
return try await wrapPowerSyncException {
try safeCast(
await kotlinDatabase.writeTransaction(
callback: TransactionCallback(
callback: callback
)
callback: wrapTransactionContext(callback: callback)
),
to: R.self
)
Expand All @@ -307,9 +303,7 @@ final class KotlinPowerSyncDatabaseImpl: PowerSyncDatabaseProtocol {
return try await wrapPowerSyncException {
try safeCast(
await kotlinDatabase.readLock(
callback: LockCallback(
callback: callback
)
callback: wrapLockContext(callback: callback)
),
to: R.self
)
Expand All @@ -322,9 +316,7 @@ final class KotlinPowerSyncDatabaseImpl: PowerSyncDatabaseProtocol {
return try await wrapPowerSyncException {
try safeCast(
await kotlinDatabase.readTransaction(
callback: TransactionCallback(
callback: callback
)
callback: wrapTransactionContext(callback: callback)
),
to: R.self
)
Expand Down Expand Up @@ -372,11 +364,11 @@ final class KotlinPowerSyncDatabaseImpl: PowerSyncDatabaseProtocol {
}
)

let rootPages = rows.compactMap { r in
if (r.opcode == "OpenRead" || r.opcode == "OpenWrite") &&
r.p3 == 0 && r.p2 != 0
let rootPages = rows.compactMap { row in
if (row.opcode == "OpenRead" || row.opcode == "OpenWrite") &&
row.p3 == 0 && row.p2 != 0
{
return r.p2
return row.p2
}
return nil
}
Expand All @@ -389,7 +381,7 @@ final class KotlinPowerSyncDatabaseImpl: PowerSyncDatabaseProtocol {
message: "Failed to convert pages data to UTF-8 string"
)
}

let tableRows = try await getAll(
sql: "SELECT tbl_name FROM sqlite_master WHERE rootpage IN (SELECT json_each.value FROM json_each(?))",
parameters: [
Expand All @@ -414,3 +406,50 @@ private struct ExplainQueryResult {
let p2: Int64
let p3: Int64
}

extension Error {
func toPowerSyncError() -> PowerSyncKotlin.PowerSyncException {
return PowerSyncKotlin.PowerSyncException(
message: localizedDescription,
cause: PowerSyncKotlin.KotlinThrowable(message: localizedDescription)
)
}
}

func wrapLockContext(
callback: @escaping (any ConnectionContext) throws -> Any
) throws -> PowerSyncKotlin.ThrowableLockCallback {
PowerSyncKotlin.wrapContextHandler { kotlinContext in
do {
return try PowerSyncKotlin.PowerSyncResult.Success(
value: callback(
KotlinConnectionContext(
ctx: kotlinContext
)
))
} catch {
return PowerSyncKotlin.PowerSyncResult.Failure(
exception: error.toPowerSyncError()
)
}
}
}

func wrapTransactionContext(
callback: @escaping (any Transaction) throws -> Any
) throws -> PowerSyncKotlin.ThrowableTransactionCallback {
PowerSyncKotlin.wrapTransactionContextHandler { kotlinContext in
do {
return try PowerSyncKotlin.PowerSyncResult.Success(
value: callback(
KotlinTransactionContext(
ctx: kotlinContext
)
))
} catch {
return PowerSyncKotlin.PowerSyncResult.Failure(
exception: error.toPowerSyncError()
)
}
}
}
67 changes: 0 additions & 67 deletions Sources/PowerSync/Kotlin/TransactionCallback.swift

This file was deleted.

Loading