As part of the above, I'm trying to bake in Corout...
# squarelibraries
e
As part of the above, I'm trying to bake in CoroutineDispatcher support directly to the SqlDriver so users don't have to manage that. I'm running into issues with
transaction
though, because it doesn't like the transaction escaping the thread it is started on, which is what happens with the dispatcher support (newTransaction, execute, and executeQuery use withContext to switch into the proper dispatcher). Is there any way to hook into the transacter to support this, and if not, is there any chance support for this could get added to SqlDelight?
h
We do have the same problem with the reactive driver, and it requires reworking the runtime.
e
Are there any plans for that, and/or are you looking for someone to do the work there?
h
The biggest question is do we want to break the runtime.
e
Was it already determined that breaking the ABI is the only way to do it? I can put some thought into doing it a backwards compatible way.
OK I see that
Transacter.Transaction
is used as the return type for
newTransaction
and
TransactionWrapper
uses it directly as well. I thought they were using a common interface. So I guess yeah the only "correct" way to deal with this would be to break the runtime.
h
Yes 😐
e
It's kind of a weird idea, but what about adding something like this to the runtime:
Copy code
interface TransactionContextProvider {
  suspend fun <R> withTransactionContext(block: suspend () -> R): R
}
and then updating
SuspendingTransacterImpl
to check if
driver is TransactionContextProvider
, and wrapping
transactionWithWrapper
in
driver.withTransactionContext
. It makes the behavior opt-in at the driver level, and puts the onus of implementation details onto the driver.