@@ -25,7 +25,7 @@ final class KotlinPowerSyncDatabaseImpl: PowerSyncDatabaseProtocol {
25
25
func waitForFirstSync( ) async throws {
26
26
try await kotlinDatabase. waitForFirstSync ( )
27
27
}
28
-
28
+
29
29
func waitForFirstSync( priority: Int32 ) async throws {
30
30
try await kotlinDatabase. waitForFirstSync ( priority: priority)
31
31
}
@@ -173,58 +173,55 @@ final class KotlinPowerSyncDatabaseImpl: PowerSyncDatabaseProtocol {
173
173
parameters: [ Any ] ? ,
174
174
mapper: @escaping ( SqlCursor ) throws -> RowType
175
175
) throws -> AsyncThrowingStream < [ RowType ] , Error > {
176
- try watch ( options: WatchOptions ( sql: sql, parameters: parameters, mapper: mapper) )
177
- }
178
-
179
- func watch< RowType> (
180
- options: WatchOptions < RowType >
181
- ) throws -> AsyncThrowingStream < [ RowType ] , Error > {
182
- AsyncThrowingStream { continuation in
183
- Task {
184
- do {
185
- var mapperError : Error ?
186
- // HACK!
187
- // SKIEE doesn't support custom exceptions in Flows
188
- // Exceptions which occur in the Flow itself cause runtime crashes.
189
- // The most probable crash would be the internal EXPLAIN statement.
190
- // This attempts to EXPLAIN the query before passing it to Kotlin
191
- // We could introduce an onChange API in Kotlin which we use to implement watches here.
192
- // This would prevent most issues with exceptions.
193
- _ = try await self . kotlinDatabase. get ( sql: " EXPLAIN \( options. sql) " , parameters: options. parameters, mapper: { _ in " " } )
194
- for try await values in try self . kotlinDatabase. watch (
195
- sql: options. sql,
196
- parameters: options. parameters,
197
- throttleMs: KotlinLong ( value: options. throttleMs) ,
198
- mapper: { cursor in do {
199
- return try options. mapper ( cursor)
200
- } catch {
201
- mapperError = error
202
- // The value here does not matter. We will throw the exception later
203
- // This is not ideal, this is only a workaround until we expose fine grained access to Kotlin SDK internals.
204
- return nil as RowType ?
205
- } }
206
- ) {
207
- if mapperError != nil {
208
- throw mapperError!
209
- }
210
- try continuation. yield ( safeCast ( values, to: [ RowType ] . self) )
176
+ try watch ( options: WatchOptions ( sql: sql, parameters: parameters, mapper: mapper) )
177
+ }
178
+
179
+ func watch< RowType> (
180
+ options: WatchOptions < RowType >
181
+ ) throws -> AsyncThrowingStream < [ RowType ] , Error > {
182
+ AsyncThrowingStream { continuation in
183
+ Task {
184
+ do {
185
+ var mapperError : Error ?
186
+ // HACK!
187
+ // SKIEE doesn't support custom exceptions in Flows
188
+ // Exceptions which occur in the Flow itself cause runtime crashes.
189
+ // The most probable crash would be the internal EXPLAIN statement.
190
+ // This attempts to EXPLAIN the query before passing it to Kotlin
191
+ // We could introduce an onChange API in Kotlin which we use to implement watches here.
192
+ // This would prevent most issues with exceptions.
193
+ _ = try await self . kotlinDatabase. getAll ( sql: " EXPLAIN \( options. sql) " , parameters: options. parameters, mapper: { _ in " " } )
194
+ for try await values in try self . kotlinDatabase. watch (
195
+ sql: options. sql,
196
+ parameters: options. parameters,
197
+ throttleMs: KotlinLong ( value: options. throttleMs) ,
198
+ mapper: { cursor in do {
199
+ return try options. mapper ( cursor)
200
+ } catch {
201
+ mapperError = error
202
+ // The value here does not matter. We will throw the exception later
203
+ // This is not ideal, this is only a workaround until we expose fine grained access to Kotlin SDK internals.
204
+ return nil as RowType ?
205
+ } }
206
+ ) {
207
+ if mapperError != nil {
208
+ throw mapperError!
211
209
}
212
- continuation. finish ( )
213
- } catch {
214
- continuation. finish ( throwing: error)
210
+ try continuation. yield ( safeCast ( values, to: [ RowType ] . self) )
215
211
}
212
+ continuation. finish ( )
213
+ } catch {
214
+ continuation. finish ( throwing: error)
216
215
}
217
216
}
218
217
}
219
-
220
-
221
- func writeTransaction< R> ( callback: @escaping ( any PowerSyncTransaction ) throws -> R ) async throws -> R {
222
- return try safeCast ( await kotlinDatabase. writeTransaction ( callback: TransactionCallback ( callback: callback) ) , to: R . self)
223
- }
224
-
225
- func readTransaction< R> ( callback: @escaping ( any PowerSyncTransaction ) throws -> R ) async throws -> R {
226
- return try safeCast ( await kotlinDatabase. readTransaction ( callback: TransactionCallback ( callback: callback) ) , to: R . self)
227
- }
228
-
229
- }
218
+ }
230
219
220
+ func writeTransaction< R> ( callback: @escaping ( any PowerSyncTransaction ) throws -> R ) async throws -> R {
221
+ return try safeCast ( await kotlinDatabase. writeTransaction ( callback: TransactionCallback ( callback: callback) ) , to: R . self)
222
+ }
223
+
224
+ func readTransaction< R> ( callback: @escaping ( any PowerSyncTransaction ) throws -> R ) async throws -> R {
225
+ return try safeCast ( await kotlinDatabase. readTransaction ( callback: TransactionCallback ( callback: callback) ) , to: R . self)
226
+ }
227
+ }
0 commit comments