Official stance on suspend support ? #5093
Replies: 2 comments 1 reply
-
There is no Sqlite, for example, is a synchronous database. Thus, the APIs to interact with it from SQL Delight are also synchronous. The advantage of providing a synchronous API is that you can batch multiple database operations to occur with a single thread hop rather than having to ping-pong from the caller's dispatcher to the IO dispatcher for every operation. Additionally, synchronous databases almost always use thread-confined connections which means transactions only work from a single thread. Since a dispatcher does not guarantee on which thread you will run, you have to do a second dispatch to a thread-confined executor when within a transaction. If the database is asynchronous (or at least the driver is), the functions can be generated as suspending. Unlike simply wrapping everything with There are no plans to do what Room is doing. In general we recommend observing queries with flows and batching mutating operations with explicit thread hops, potentially even using a dedicated dispatcher which runs on a single thread to avoid contention. |
Beta Was this translation helpful? Give feedback.
-
Thanks @JakeWharton for the detailed answer. I would recommend you folks to update the official sample app that is in the sqldelight repository so that some usage patterns can be demonstrated The current sample app is pretty outdated (it uses multiple activities) and it accesses the database on the main thread. There are not of guesses and estimates about the proper usage pattern of sqldelight in the community and it would really help if you folks could alot some engineers to create a NowInAndroid kind of application depicting various usecases. Thank you |
Beta Was this translation helpful? Give feedback.
-
I have seen discussions regarding Flows support for Sqldelight , however I am yet to find anything concrete on supporting suspending queries , like we have in Room Dao .
Basically my question is that does the code below suffice ?
OR i would have to manually provide the context each time i access the db like the code below ?
unfortunately the lack of discussion on this makes me worried if we should even be adopting SqlDelight for our projects, despite the teams strong inclination towards this .
Please advise folks
Beta Was this translation helpful? Give feedback.
All reactions