Skip to content

Commit 7564051

Browse files
DominicGBauerDominicGBauer
andauthored
fix: transactions resulting in error when using different threads (#81)
* fix: tranasactions resulting in error when using different threads * fix: transactions issue * chore: remove public * docs: update changelog --------- Co-authored-by: DominicGBauer <[email protected]>
1 parent d12789d commit 7564051

File tree

7 files changed

+39
-55
lines changed

7 files changed

+39
-55
lines changed

CHANGELOG.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
# Changelog
22

3+
## 1.0.0-BETA9
4+
5+
* Re-enable SKIE `SuspendInterop`
6+
* Move transaction functions out of `PowerSyncTransactionFactory` to avoid threading issues in Swift SDK
7+
38
## 1.0.0-BETA8
49

5-
* Disable Skie `SuspendInterop` plugin to fix overriding `suspend` functions in Swift
10+
* Disable SKIE `SuspendInterop` plugin to fix overriding `suspend` functions in Swift
611

712
## 1.0.0-BETA7
813

914
* Update supabase connector to use supabase-kt version 3
10-
* Handle postgres error codes in supabase connector
15+
* Handle Postgres error codes in supabase connector
1116

1217
## 1.0.0-BETA6
1318

PowerSync/build.gradle.kts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,6 @@ kotlin {
4141
}
4242
}
4343

44-
skie {
45-
features {
46-
group {
47-
// We turn this off as the suspend interop feature results in
48-
// threading issues when implementing SDK in Swift
49-
SuspendInterop.Enabled(false)
50-
}
51-
}
52-
}
53-
5444
kmmbridge {
5545
artifactManager.set(SonatypePortalPublishArtifactManager(project, repositoryName = null))
5646
artifactManager.finalizeValue()

core/src/commonMain/kotlin/com/powersync/db/PowerSyncDatabaseImpl.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import app.cash.sqldelight.async.coroutines.awaitAsList
44
import app.cash.sqldelight.async.coroutines.awaitAsOne
55
import app.cash.sqldelight.db.SqlCursor
66
import co.touchlab.kermit.Logger
7+
import co.touchlab.skie.configuration.annotations.SuspendInterop
78
import com.powersync.DatabaseDriverFactory
89
import com.powersync.PowerSyncDatabase
910
import com.powersync.PsSqlDriver

core/src/commonMain/kotlin/com/powersync/db/internal/InternalDatabaseImpl.kt

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import app.cash.sqldelight.coroutines.mapToList
99
import app.cash.sqldelight.db.QueryResult
1010
import app.cash.sqldelight.db.SqlCursor
1111
import app.cash.sqldelight.db.SqlPreparedStatement
12-
import com.powersync.PowerSyncTransaction
12+
import com.persistence.PowersyncQueries
1313
import com.powersync.PsSqlDriver
1414
import com.powersync.persistence.PsDatabase
1515
import com.powersync.utils.JsonUtil
@@ -27,11 +27,36 @@ internal class InternalDatabaseImpl(
2727
private val scope: CoroutineScope,
2828
) : InternalDatabase {
2929
override val transactor: PsDatabase = PsDatabase(driver)
30-
override val queries = transactor.powersyncQueries
30+
override val queries: PowersyncQueries = transactor.powersyncQueries
31+
private val transaction =
32+
object : PowerSyncTransaction {
33+
override suspend fun execute(
34+
sql: String,
35+
parameters: List<Any?>?,
36+
): Long = this@InternalDatabaseImpl.execute(sql, parameters ?: emptyList())
37+
38+
override suspend fun <RowType : Any> get(
39+
sql: String,
40+
parameters: List<Any?>?,
41+
mapper: (SqlCursor) -> RowType,
42+
): RowType = this@InternalDatabaseImpl.get(sql, parameters ?: emptyList(), mapper)
43+
44+
override suspend fun <RowType : Any> getAll(
45+
sql: String,
46+
parameters: List<Any?>?,
47+
mapper: (SqlCursor) -> RowType,
48+
): List<RowType> = this@InternalDatabaseImpl.getAll(sql, parameters ?: emptyList(), mapper)
49+
50+
override suspend fun <RowType : Any> getOptional(
51+
sql: String,
52+
parameters: List<Any?>?,
53+
mapper: (SqlCursor) -> RowType,
54+
): RowType? = this@InternalDatabaseImpl.getOptional(sql, parameters ?: emptyList(), mapper)
55+
}
3156

3257
companion object {
33-
const val POWERSYNC_TABLE_MATCH = "(^ps_data__|^ps_data_local__)"
34-
const val DEFAULT_WATCH_THROTTLE_MS = 30L
58+
const val POWERSYNC_TABLE_MATCH: String = "(^ps_data__|^ps_data_local__)"
59+
const val DEFAULT_WATCH_THROTTLE_MS: Long = 30L
3560
}
3661

3762
init {
@@ -159,13 +184,11 @@ internal class InternalDatabaseImpl(
159184

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

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

core/src/commonMain/kotlin/com/powersync/db/internal/PowerSyncTransactionFactory.kt

Lines changed: 0 additions & 35 deletions
This file was deleted.

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ development=true
1717
RELEASE_SIGNING_ENABLED=true
1818
# Library config
1919
GROUP=com.powersync
20-
LIBRARY_VERSION=1.0.0-BETA8
20+
LIBRARY_VERSION=1.0.0-BETA9
2121
GITHUB_REPO=https://github.com/powersync-ja/powersync-kotlin.git
2222
# POM
2323
POM_URL=https://github.com/powersync-ja/powersync-kotlin/

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ compose-preview = "1.7.2"
2929
# plugins
3030
android-gradle-plugin = "8.5.1"
3131
kmmBridge = "0.5.7"
32-
skie = "0.9.3"
32+
skie = "0.9.5"
3333
maven-publish = "0.27.0"
3434
download-plugin = "5.5.0"
3535
grammerKit = "0.1.12"

0 commit comments

Comments
 (0)