Kev
10/19/2024, 7:26 AMKev
10/19/2024, 7:28 AMsuspend fun persist(foo: String): Either<Error, Unit> = either {
// Raise context may escape through this lambda
database.transaction {
val id = repository.insertFoo(foo).bind()
if (id == 0) {
rollback()
raise(Error("Failed to insert foo"))
}
}
}
Alejandro Serrano.Mena
10/21/2024, 7:26 AMtransaction
actually does. If the transaction is run in place, then doing what you do is fine
otherwise, another option is to hook at some kind of callback (which I don't know if they exist in SQLDelight). Something along the lines of:
database.transaction {
val id = repository.insertFoo(foo).bind()
if (id == 0) rollback()
}.onRollback { raise(...) }
Kev
10/21/2024, 9:28 AMAlejandro Serrano.Mena
10/21/2024, 9:29 AMtransaction
better into account, feel free to open an issue and we can explore it