diff --git a/Package.swift b/Package.swift index 5f0267b9..beeff0d6 100644 --- a/Package.swift +++ b/Package.swift @@ -21,4 +21,4 @@ let package = Package( ) , ] -) +) \ No newline at end of file diff --git a/core/src/commonMain/kotlin/com/powersync/db/PowerSyncDatabaseImpl.kt b/core/src/commonMain/kotlin/com/powersync/db/PowerSyncDatabaseImpl.kt index ac0752c9..f219f0ce 100644 --- a/core/src/commonMain/kotlin/com/powersync/db/PowerSyncDatabaseImpl.kt +++ b/core/src/commonMain/kotlin/com/powersync/db/PowerSyncDatabaseImpl.kt @@ -153,6 +153,7 @@ internal class PowerSyncDatabaseImpl( return@readTransaction CrudTransaction( crud = entries, transactionId = txId, complete = { writeCheckpoint -> + println("[CrudTransaction::complete] Completing transaction with checkpoint $writeCheckpoint") handleWriteCheckpoint(entries.last().clientId, writeCheckpoint) } ) @@ -208,6 +209,10 @@ internal class PowerSyncDatabaseImpl( return internalDb.execute(sql, parameters) } + override suspend fun executeWrite(sql: String, parameters: List?): Long { + return internalDb.executeWrite(sql, parameters) + } + private suspend fun handleWriteCheckpoint(lastTransactionId: Int, writeCheckpoint: String?) { writeTransaction { internalDb.queries.deleteEntriesWithIdLessThan(lastTransactionId.toLong()) diff --git a/core/src/commonMain/kotlin/com/powersync/db/WriteQueries.kt b/core/src/commonMain/kotlin/com/powersync/db/WriteQueries.kt index 544c2409..9fdca086 100644 --- a/core/src/commonMain/kotlin/com/powersync/db/WriteQueries.kt +++ b/core/src/commonMain/kotlin/com/powersync/db/WriteQueries.kt @@ -9,6 +9,8 @@ interface WriteQueries { */ suspend fun execute(sql: String, parameters: List? = listOf()): Long + suspend fun executeWrite(sql: String, parameters: List?): Long + suspend fun writeTransaction(body: suspend SuspendingTransactionWithReturn.() -> R): R } \ No newline at end of file diff --git a/core/src/commonMain/kotlin/com/powersync/db/internal/PsInternalDatabase.kt b/core/src/commonMain/kotlin/com/powersync/db/internal/PsInternalDatabase.kt index 3d908886..6d827c29 100644 --- a/core/src/commonMain/kotlin/com/powersync/db/internal/PsInternalDatabase.kt +++ b/core/src/commonMain/kotlin/com/powersync/db/internal/PsInternalDatabase.kt @@ -167,6 +167,12 @@ class PsInternalDatabase(val driver: PsSqlDriver, private val scope: CoroutineSc return transactor.transactionWithResult(noEnclosing = true, body) } + override suspend fun executeWrite(sql: String, parameters: List?): Long { + return writeTransaction { + execute(sql, parameters) + } + } + // Register callback for table updates private fun tableUpdates(): Flow> { return driver.tableUpdates()