How to perform queries in background thread?
Asked Answered
P

1

7

I'm currently looking at having a KMM application backed by SQLdelight for all domain-related operations.

SQLdelight seems to provide really nice interfaces, however it seems like all the write calls (insert/update/delete) are implemented using blocking calls, so I'm worried that it would hurt the responsiveness of the app by blocking the main thread a lot.

Is there a recommended way to perform such operations without blocking the main thread?

The app would have to work on iOS as well, so I can't afford freezing too much.

Prismatic answered 23/4, 2021 at 15:6 Comment(0)
M
0

A bit late to answer but it might be useful for others:

You should use wiwthContext(Dispatchers.Default) assuming you are using the native-mt version of coroutine libraries. That allow you to ensure insert/update/delete are not executed on the main thread.

You also have the possibility of using sqldelight coroutine-extensions library to return a flow from your queries to observe changes in your database.

Marrin answered 4/4, 2022 at 8:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.