Hi I am trying to use context receivers with Expos...
# server
l
Hi I am trying to use context receivers with Exposed in order to pass the transaction What would be great, would be to have optionally a transaction in the context, something like
Copy code
context(Transaction?)
fun doStatementReuseOrCreateTransaction(statement: suspend Transaction.() -> Unit) {
  if (this@Transaction == null) {
    openTransaction {
      statement()
    }
  } else statement()
}
However as soon as I make the context optional (with the
?
) then intellij is lost and doesn't understand
this@Transaction
anymore is there any way to make it work?
d
If you create an interface to wrap your transaction and then pass that as the context, you should be able to implement it in 2 ways - one using a transaction and one not. 🙃
l
😅 so easy trick thanks!
🙃 1
d
(there's an entire few videos on this technique)
👯‍♂️ 1
🆒 1