Skip to content

fix: transactions resulting in error when using different threads #81

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 4, 2024
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
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
# Changelog

## 1.0.0-BETA9

* Re-enable SKIE `SuspendInterop`
* Move transaction functions out of `PowerSyncTransactionFactory` to avoid threading issues in Swift SDK

## 1.0.0-BETA8

* Disable Skie `SuspendInterop` plugin to fix overriding `suspend` functions in Swift
* Disable SKIE `SuspendInterop` plugin to fix overriding `suspend` functions in Swift

## 1.0.0-BETA7

* Update supabase connector to use supabase-kt version 3
* Handle postgres error codes in supabase connector
* Handle Postgres error codes in supabase connector

## 1.0.0-BETA6

Expand Down
10 changes: 0 additions & 10 deletions PowerSync/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,6 @@ kotlin {
}
}

skie {
features {
group {
// We turn this off as the suspend interop feature results in
// threading issues when implementing SDK in Swift
SuspendInterop.Enabled(false)
}
}
}

kmmbridge {
artifactManager.set(SonatypePortalPublishArtifactManager(project, repositoryName = null))
artifactManager.finalizeValue()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import app.cash.sqldelight.async.coroutines.awaitAsList
import app.cash.sqldelight.async.coroutines.awaitAsOne
import app.cash.sqldelight.db.SqlCursor
import co.touchlab.kermit.Logger
import co.touchlab.skie.configuration.annotations.SuspendInterop
import com.powersync.DatabaseDriverFactory
import com.powersync.PowerSyncDatabase
import com.powersync.PsSqlDriver
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import app.cash.sqldelight.coroutines.mapToList
import app.cash.sqldelight.db.QueryResult
import app.cash.sqldelight.db.SqlCursor
import app.cash.sqldelight.db.SqlPreparedStatement
import com.powersync.PowerSyncTransaction
import com.persistence.PowersyncQueries
import com.powersync.PsSqlDriver
import com.powersync.persistence.PsDatabase
import com.powersync.utils.JsonUtil
Expand All @@ -27,11 +27,36 @@ internal class InternalDatabaseImpl(
private val scope: CoroutineScope,
) : InternalDatabase {
override val transactor: PsDatabase = PsDatabase(driver)
override val queries = transactor.powersyncQueries
override val queries: PowersyncQueries = transactor.powersyncQueries
private val transaction =
object : PowerSyncTransaction {
override suspend fun execute(
sql: String,
parameters: List<Any?>?,
): Long = [email protected](sql, parameters ?: emptyList())

override suspend fun <RowType : Any> get(
sql: String,
parameters: List<Any?>?,
mapper: (SqlCursor) -> RowType,
): RowType = [email protected](sql, parameters ?: emptyList(), mapper)

override suspend fun <RowType : Any> getAll(
sql: String,
parameters: List<Any?>?,
mapper: (SqlCursor) -> RowType,
): List<RowType> = [email protected](sql, parameters ?: emptyList(), mapper)

override suspend fun <RowType : Any> getOptional(
sql: String,
parameters: List<Any?>?,
mapper: (SqlCursor) -> RowType,
): RowType? = [email protected](sql, parameters ?: emptyList(), mapper)
}

companion object {
const val POWERSYNC_TABLE_MATCH = "(^ps_data__|^ps_data_local__)"
const val DEFAULT_WATCH_THROTTLE_MS = 30L
const val POWERSYNC_TABLE_MATCH: String = "(^ps_data__|^ps_data_local__)"
const val DEFAULT_WATCH_THROTTLE_MS: Long = 30L
}

init {
Expand Down Expand Up @@ -159,13 +184,11 @@ internal class InternalDatabaseImpl(

override suspend fun <R> readTransaction(callback: suspend (PowerSyncTransaction) -> R): R =
transactor.transactionWithResult(noEnclosing = true) {
val transaction = PowerSyncTransaction(this@InternalDatabaseImpl)
callback(transaction)
}

override suspend fun <R> writeTransaction(callback: suspend (PowerSyncTransaction) -> R): R =
transactor.transactionWithResult(noEnclosing = true) {
val transaction = PowerSyncTransaction(this@InternalDatabaseImpl)
callback(transaction)
}

Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ development=true
RELEASE_SIGNING_ENABLED=true
# Library config
GROUP=com.powersync
LIBRARY_VERSION=1.0.0-BETA8
LIBRARY_VERSION=1.0.0-BETA9
GITHUB_REPO=https://github.com/powersync-ja/powersync-kotlin.git
# POM
POM_URL=https://github.com/powersync-ja/powersync-kotlin/
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ compose-preview = "1.7.2"
# plugins
android-gradle-plugin = "8.5.1"
kmmBridge = "0.5.7"
skie = "0.9.3"
skie = "0.9.5"
maven-publish = "0.27.0"
download-plugin = "5.5.0"
grammerKit = "0.1.12"
Expand Down
Loading