@@ -20,7 +20,7 @@ final class KotlinPowerSyncDatabaseImpl: PowerSyncDatabaseProtocol {
2020 logger: logger. kLogger
2121 )
2222 self . logger = logger
23- self . currentStatus = KotlinSyncStatus (
23+ currentStatus = KotlinSyncStatus (
2424 baseStatus: kotlinDatabase. currentStatus
2525 )
2626 }
@@ -30,18 +30,22 @@ final class KotlinPowerSyncDatabaseImpl: PowerSyncDatabaseProtocol {
3030 }
3131
3232 func updateSchema( schema: any SchemaProtocol ) async throws {
33- try await kotlinDatabase. updateSchema ( schema: KotlinAdapter . Schema. toKotlin ( schema) )
33+ try await kotlinDatabase. updateSchema (
34+ schema: KotlinAdapter . Schema. toKotlin ( schema)
35+ )
3436 }
3537
3638 func waitForFirstSync( priority: Int32 ) async throws {
37- try await kotlinDatabase. waitForFirstSync ( priority: priority)
39+ try await kotlinDatabase. waitForFirstSync (
40+ priority: priority
41+ )
3842 }
3943
4044 func connect(
4145 connector: PowerSyncBackendConnector ,
4246 crudThrottleMs: Int64 = 1000 ,
4347 retryDelayMs: Int64 = 5000 ,
44- params: [ String : JsonParam ? ] = [ : ]
48+ params: JsonParam = [ : ]
4549 ) async throws {
4650 let connectorAdapter = PowerSyncBackendConnectorAdapter (
4751 swiftBackendConnector: connector,
@@ -52,22 +56,27 @@ final class KotlinPowerSyncDatabaseImpl: PowerSyncDatabaseProtocol {
5256 connector: connectorAdapter,
5357 crudThrottleMs: crudThrottleMs,
5458 retryDelayMs: retryDelayMs,
55- params: params
59+ // We map to basic values and use NSNull to avoid SKIEE thinking the values must be of Any type
60+ params: params. mapValues { $0. toValue ( ) ?? NSNull ( ) }
5661 )
5762 }
5863
5964 func getCrudBatch( limit: Int32 = 100 ) async throws -> CrudBatch ? {
6065 guard let base = try await kotlinDatabase. getCrudBatch ( limit: limit) else {
6166 return nil
6267 }
63- return try KotlinCrudBatch ( base)
68+ return try KotlinCrudBatch (
69+ batch: base
70+ )
6471 }
6572
6673 func getNextCrudTransaction( ) async throws -> CrudTransaction ? {
6774 guard let base = try await kotlinDatabase. getNextCrudTransaction ( ) else {
6875 return nil
6976 }
70- return try KotlinCrudTransaction ( base)
77+ return try KotlinCrudTransaction (
78+ transaction: base
79+ )
7180 }
7281
7382 func getPowerSyncVersion( ) async throws -> String {
@@ -85,7 +94,7 @@ final class KotlinPowerSyncDatabaseImpl: PowerSyncDatabaseProtocol {
8594 }
8695
8796 func execute( sql: String , parameters: [ Any ? ] ? ) async throws -> Int64 {
88- try await writeTransaction { ctx in
97+ try await writeTransaction { ctx in
8998 try ctx. execute (
9099 sql: sql,
91100 parameters: parameters
@@ -98,7 +107,7 @@ final class KotlinPowerSyncDatabaseImpl: PowerSyncDatabaseProtocol {
98107 parameters: [ Any ? ] ? ,
99108 mapper: @escaping ( SqlCursor ) -> RowType
100109 ) async throws -> RowType {
101- try await readTransaction { ctx in
110+ try await readLock { ctx in
102111 try ctx. get (
103112 sql: sql,
104113 parameters: parameters,
@@ -112,7 +121,7 @@ final class KotlinPowerSyncDatabaseImpl: PowerSyncDatabaseProtocol {
112121 parameters: [ Any ? ] ? ,
113122 mapper: @escaping ( SqlCursor ) throws -> RowType
114123 ) async throws -> RowType {
115- try await readTransaction { ctx in
124+ try await readLock { ctx in
116125 try ctx. get (
117126 sql: sql,
118127 parameters: parameters,
@@ -126,7 +135,7 @@ final class KotlinPowerSyncDatabaseImpl: PowerSyncDatabaseProtocol {
126135 parameters: [ Any ? ] ? ,
127136 mapper: @escaping ( SqlCursor ) -> RowType
128137 ) async throws -> [ RowType ] {
129- try await readTransaction { ctx in
138+ try await readLock { ctx in
130139 try ctx. getAll (
131140 sql: sql,
132141 parameters: parameters,
@@ -140,7 +149,7 @@ final class KotlinPowerSyncDatabaseImpl: PowerSyncDatabaseProtocol {
140149 parameters: [ Any ? ] ? ,
141150 mapper: @escaping ( SqlCursor ) throws -> RowType
142151 ) async throws -> [ RowType ] {
143- try await readTransaction { ctx in
152+ try await readLock { ctx in
144153 try ctx. getAll (
145154 sql: sql,
146155 parameters: parameters,
@@ -154,7 +163,7 @@ final class KotlinPowerSyncDatabaseImpl: PowerSyncDatabaseProtocol {
154163 parameters: [ Any ? ] ? ,
155164 mapper: @escaping ( SqlCursor ) -> RowType
156165 ) async throws -> RowType ? {
157- try await readTransaction { ctx in
166+ try await readLock { ctx in
158167 try ctx. getOptional (
159168 sql: sql,
160169 parameters: parameters,
@@ -168,15 +177,15 @@ final class KotlinPowerSyncDatabaseImpl: PowerSyncDatabaseProtocol {
168177 parameters: [ Any ? ] ? ,
169178 mapper: @escaping ( SqlCursor ) throws -> RowType
170179 ) async throws -> RowType ? {
171- try await readTransaction { ctx in
180+ try await readLock { ctx in
172181 try ctx. getOptional (
173182 sql: sql,
174183 parameters: parameters,
175184 mapper: mapper
176185 )
177186 }
178187 }
179-
188+
180189 func watch< RowType> (
181190 sql: String ,
182191 parameters: [ Any ? ] ? ,
@@ -268,7 +277,22 @@ final class KotlinPowerSyncDatabaseImpl: PowerSyncDatabaseProtocol {
268277 }
269278 }
270279
271- func writeTransaction< R> ( callback: @escaping ( any ConnectionContext ) throws -> R ) async throws -> R {
280+ func writeLock< R> (
281+ callback: @escaping ( any ConnectionContext ) throws -> R
282+ ) async throws -> R {
283+ return try safeCast (
284+ await kotlinDatabase. writeLock (
285+ callback: LockCallback (
286+ callback: callback
287+ )
288+ ) ,
289+ to: R . self
290+ )
291+ }
292+
293+ func writeTransaction< R> (
294+ callback: @escaping ( any Transaction ) throws -> R
295+ ) async throws -> R {
272296 return try safeCast (
273297 await kotlinDatabase. writeTransaction (
274298 callback: TransactionCallback (
@@ -279,7 +303,24 @@ final class KotlinPowerSyncDatabaseImpl: PowerSyncDatabaseProtocol {
279303 )
280304 }
281305
282- func readTransaction< R> ( callback: @escaping ( any ConnectionContext ) throws -> R ) async throws -> R {
306+ func readLock< R> (
307+ callback: @escaping ( any ConnectionContext ) throws -> R
308+ )
309+ async throws -> R
310+ {
311+ return try safeCast (
312+ await kotlinDatabase. readLock (
313+ callback: LockCallback (
314+ callback: callback
315+ )
316+ ) ,
317+ to: R . self
318+ )
319+ }
320+
321+ func readTransaction< R> (
322+ callback: @escaping ( any Transaction ) throws -> R
323+ ) async throws -> R {
283324 return try safeCast (
284325 await kotlinDatabase. readTransaction (
285326 callback: TransactionCallback (
0 commit comments