Hey guys, I'm trying to implement use `generateAsy...
# squarelibraries
o
Hey guys, I'm trying to implement use
generateAsync
with SQLDelight with a PostgreSQL database. But I can't seem to find docs on how to create the R2BCDriver. Up until now I had HikariCP with
.asJdbcDriver()
extension. My main problem comes down to doing a transaction over multiple "DAOs" If have
aDAO
&
bDAO
and they both expose suspend functions such as:
suspend someQuery() = withContext(<http://Dispatchers.IO|Dispatchers.IO>) { queries.bla() }
I now want to create a transaction in a place where I inject both DAOs to perform a job, and make sure both functions are under a transaction. The problem is that Dataabase.transaction's lambda block doesn't support suspending calls.. What's the recommended approach? Thanks!
Ping. no one?
h
You should not mix JDBC with R2DBC. I wonder, how you managed to actually create the hdbc datasource using r2dbc driver. Anyway, there is currently no R2DBC ConnectionFactory support, it requires runtime api changes.
Regarding suspend support: the SuspenTransaction does support suspend transactions 🤔
o
Hey @hfhbd, thanks for the reply 🙂 I think I may have mixed some stuff. Let me explain it better. I didn't manage to create a R2DBC driver - What I mean that if I would have gotten it to work with a connection pool and all of that, I could've used the SuspendTransaction as you've stated. But since I couldn't and I'm still using a "regular" HikariCP connection pool with the .asJdbcDriver function then I obviously don't have a SuspendTransaction (I have the regular one). So, with that in mind: My question is how can I create a transaction over multiple "DAOs" If have
aDAO
&
bDAO
and they both expose suspend functions such as:
suspend someQuery() = withContext(<http://Dispatchers.IO|Dispatchers.IO>) { queries.bla() }
And I want to use them under one class which injects both and execute them both under a single transaction, e.g.:
Copy code
class Something(val aDao: ADao, val bDao: BDao) {
   fun invoke() {
      transaction {
         aDao.something()
         bDao.something()
      }
   }
}
To get the transaction lambda I can simply inject a Transacter and use it - the problem as I've stated, I cannot use suspending functions within the current lambda
h
Well it’s not possible, you need to call the sql queries directly without the suspend mapper.
🙌 1