@@ -20,7 +20,7 @@ final class KotlinPowerSyncDatabaseImpl: PowerSyncDatabaseProtocol {
20
20
logger: logger. kLogger
21
21
)
22
22
self . logger = logger
23
- self . currentStatus = KotlinSyncStatus (
23
+ currentStatus = KotlinSyncStatus (
24
24
baseStatus: kotlinDatabase. currentStatus
25
25
)
26
26
}
@@ -30,18 +30,22 @@ final class KotlinPowerSyncDatabaseImpl: PowerSyncDatabaseProtocol {
30
30
}
31
31
32
32
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
+ )
34
36
}
35
37
36
38
func waitForFirstSync( priority: Int32 ) async throws {
37
- try await kotlinDatabase. waitForFirstSync ( priority: priority)
39
+ try await kotlinDatabase. waitForFirstSync (
40
+ priority: priority
41
+ )
38
42
}
39
43
40
44
func connect(
41
45
connector: PowerSyncBackendConnector ,
42
46
crudThrottleMs: Int64 = 1000 ,
43
47
retryDelayMs: Int64 = 5000 ,
44
- params: [ String : JsonParam ? ] = [ : ]
48
+ params: JsonParam = [ : ]
45
49
) async throws {
46
50
let connectorAdapter = PowerSyncBackendConnectorAdapter (
47
51
swiftBackendConnector: connector,
@@ -52,22 +56,27 @@ final class KotlinPowerSyncDatabaseImpl: PowerSyncDatabaseProtocol {
52
56
connector: connectorAdapter,
53
57
crudThrottleMs: crudThrottleMs,
54
58
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 ( ) }
56
61
)
57
62
}
58
63
59
64
func getCrudBatch( limit: Int32 = 100 ) async throws -> CrudBatch ? {
60
65
guard let base = try await kotlinDatabase. getCrudBatch ( limit: limit) else {
61
66
return nil
62
67
}
63
- return try KotlinCrudBatch ( base)
68
+ return try KotlinCrudBatch (
69
+ batch: base
70
+ )
64
71
}
65
72
66
73
func getNextCrudTransaction( ) async throws -> CrudTransaction ? {
67
74
guard let base = try await kotlinDatabase. getNextCrudTransaction ( ) else {
68
75
return nil
69
76
}
70
- return try KotlinCrudTransaction ( base)
77
+ return try KotlinCrudTransaction (
78
+ transaction: base
79
+ )
71
80
}
72
81
73
82
func getPowerSyncVersion( ) async throws -> String {
@@ -85,7 +94,7 @@ final class KotlinPowerSyncDatabaseImpl: PowerSyncDatabaseProtocol {
85
94
}
86
95
87
96
func execute( sql: String , parameters: [ Any ? ] ? ) async throws -> Int64 {
88
- try await writeTransaction { ctx in
97
+ try await writeTransaction { ctx in
89
98
try ctx. execute (
90
99
sql: sql,
91
100
parameters: parameters
@@ -98,7 +107,7 @@ final class KotlinPowerSyncDatabaseImpl: PowerSyncDatabaseProtocol {
98
107
parameters: [ Any ? ] ? ,
99
108
mapper: @escaping ( SqlCursor ) -> RowType
100
109
) async throws -> RowType {
101
- try await readTransaction { ctx in
110
+ try await readLock { ctx in
102
111
try ctx. get (
103
112
sql: sql,
104
113
parameters: parameters,
@@ -112,7 +121,7 @@ final class KotlinPowerSyncDatabaseImpl: PowerSyncDatabaseProtocol {
112
121
parameters: [ Any ? ] ? ,
113
122
mapper: @escaping ( SqlCursor ) throws -> RowType
114
123
) async throws -> RowType {
115
- try await readTransaction { ctx in
124
+ try await readLock { ctx in
116
125
try ctx. get (
117
126
sql: sql,
118
127
parameters: parameters,
@@ -126,7 +135,7 @@ final class KotlinPowerSyncDatabaseImpl: PowerSyncDatabaseProtocol {
126
135
parameters: [ Any ? ] ? ,
127
136
mapper: @escaping ( SqlCursor ) -> RowType
128
137
) async throws -> [ RowType ] {
129
- try await readTransaction { ctx in
138
+ try await readLock { ctx in
130
139
try ctx. getAll (
131
140
sql: sql,
132
141
parameters: parameters,
@@ -140,7 +149,7 @@ final class KotlinPowerSyncDatabaseImpl: PowerSyncDatabaseProtocol {
140
149
parameters: [ Any ? ] ? ,
141
150
mapper: @escaping ( SqlCursor ) throws -> RowType
142
151
) async throws -> [ RowType ] {
143
- try await readTransaction { ctx in
152
+ try await readLock { ctx in
144
153
try ctx. getAll (
145
154
sql: sql,
146
155
parameters: parameters,
@@ -154,7 +163,7 @@ final class KotlinPowerSyncDatabaseImpl: PowerSyncDatabaseProtocol {
154
163
parameters: [ Any ? ] ? ,
155
164
mapper: @escaping ( SqlCursor ) -> RowType
156
165
) async throws -> RowType ? {
157
- try await readTransaction { ctx in
166
+ try await readLock { ctx in
158
167
try ctx. getOptional (
159
168
sql: sql,
160
169
parameters: parameters,
@@ -168,15 +177,15 @@ final class KotlinPowerSyncDatabaseImpl: PowerSyncDatabaseProtocol {
168
177
parameters: [ Any ? ] ? ,
169
178
mapper: @escaping ( SqlCursor ) throws -> RowType
170
179
) async throws -> RowType ? {
171
- try await readTransaction { ctx in
180
+ try await readLock { ctx in
172
181
try ctx. getOptional (
173
182
sql: sql,
174
183
parameters: parameters,
175
184
mapper: mapper
176
185
)
177
186
}
178
187
}
179
-
188
+
180
189
func watch< RowType> (
181
190
sql: String ,
182
191
parameters: [ Any ? ] ? ,
@@ -268,7 +277,22 @@ final class KotlinPowerSyncDatabaseImpl: PowerSyncDatabaseProtocol {
268
277
}
269
278
}
270
279
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 {
272
296
return try safeCast (
273
297
await kotlinDatabase. writeTransaction (
274
298
callback: TransactionCallback (
@@ -279,7 +303,24 @@ final class KotlinPowerSyncDatabaseImpl: PowerSyncDatabaseProtocol {
279
303
)
280
304
}
281
305
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 {
283
324
return try safeCast (
284
325
await kotlinDatabase. readTransaction (
285
326
callback: TransactionCallback (
0 commit comments