Colton Idle
08/07/2023, 8:24 PMkevin.cianfarini
08/07/2023, 8:31 PMawaitAs
for exampleColton Idle
08/07/2023, 8:32 PMkevin.cianfarini
08/07/2023, 8:34 PMFlow
extensions are based on callbacks. The items which get emitted into the flow are still executed in a blocking manner with SQLitekevin.cianfarini
08/07/2023, 8:36 PMclass MyRepository(private val ioContext: CoroutineContext, private val db: Database) {
suspend fun doTheQuery() = withContext(ioContext) {
db.someQueries.myQuery(someValue).executeAsOne()
}
}
Derek Ellis
08/07/2023, 8:42 PMColton Idle
08/07/2023, 8:42 PMwithContext
TILColton Idle
08/07/2023, 8:43 PMkevin.cianfarini
08/07/2023, 8:43 PMColton Idle
08/07/2023, 8:44 PMTo elaborate on what Kevin said, SQLDelight 2.0 introduces support for drivers that are fundamentally asynchronous (like web workers and R2DBC), and while it will wrap all of your queries in suspending functions, it does not magically make those calls non-blocking for synchronous drivers!oh. do you know if this is in some part of the docs? want to be able to point my team to it.
Colton Idle
08/07/2023, 8:44 PMColton Idle
08/07/2023, 8:46 PMgenerateAsync = true
If set to true, SQLDelight will generate suspending query methods for us with asynchronous drivers.basically pointeless to enable that if I'm just writing my app on android? (and writing my tests on jvm with in memory db?)
kevin.cianfarini
08/07/2023, 8:47 PMColton Idle
08/07/2023, 9:03 PMDerek Ellis
08/07/2023, 9:05 PMoh. do you know if this is in some part of the docs? want to be able to point my team to it.It's sort of mentioned on the migrating to 2.0 page, but it's not really emphasized. Could definitely be improved on
Colton Idle
08/08/2023, 6:13 AMColton Idle
08/08/2023, 7:48 AMDerek Ellis
08/08/2023, 11:36 AMalec
08/08/2023, 1:42 PMalec
08/08/2023, 1:42 PMColton Idle
08/08/2023, 5:08 PMkevin.cianfarini
08/08/2023, 5:22 PMkevin.cianfarini
08/08/2023, 5:24 PMalec
08/08/2023, 5:36 PMalec
08/08/2023, 5:36 PMalec
08/08/2023, 5:37 PMColton Idle
08/08/2023, 5:37 PMkevin.cianfarini
08/08/2023, 5:37 PMwithContext
calls everywhere. Might not be thinking about it enough from a testing standpoint but seems coolColton Idle
08/08/2023, 5:37 PMColton Idle
08/08/2023, 5:39 PMColton Idle
08/08/2023, 5:40 PMkevin.cianfarini
10/31/2023, 2:29 PMSqlDriver
know if a query is a write operation or not? I would think we'd want to honor those limitations in whatever internal dispatcher is used for an "async" SQLite driver?kevin.cianfarini
10/31/2023, 2:29 PMDerek Ellis
10/31/2023, 2:35 PMhow would aI don't think it would have to. The idea behind an "async" driver for Android is that there's a (bizarrely) small cap for the number of active connections a database can have. An "async" Android driver would still block a thread when reading/writing or waiting for the write lock to release, but the idea is that if the number of connections is exhausted, the driver could suspend while waiting for connections to free up, rather than just eating up threads from a thread poolknow if a query is a write operation or not?SqlDriver
kevin.cianfarini
10/31/2023, 2:36 PMkevin.cianfarini
10/31/2023, 2:37 PMDerek Ellis
10/31/2023, 2:38 PMSqlDriver
kind of differentiates between writes and reads through execute
and executeQuery
kevin.cianfarini
10/31/2023, 2:39 PMDerek Ellis
10/31/2023, 2:40 PMWouldn’t that possibly run into writer thread lock contention?It's possible! It's all kind of untested. There are also already some fatal flaws that have been exposed with the async runtime in SQLDelight, particularly around transaction handling, so at this point I think it's unlikely an async driver for Android will happen in 2.0 (if ever)
kevin.cianfarini
10/31/2023, 2:42 PMDerek Ellis
10/31/2023, 2:47 PMCoroutineContext
stuff, but it would require changes to the runtime and I haven't actually done the work to see whether or not it could be done in a non-breaking manner yet.
(me, being the main person behind the async runtime)kevin.cianfarini
10/31/2023, 2:48 PM