dbResult
Runs block and returns what it produced as a DataResult: a failure the application is expected to handle becomes DataResult.Failure, and one that means the calling code is wrong is still thrown.
One query has asResult and a transaction transactionResult; this is for anything else.
val senators: DataResult<List<Senator>> = dbResult {
db.execute {
createNativeQuery("SET LOCAL statement_timeout = 5000").execute()
createNamedQuery("SELECT id, cognomen FROM senators WHERE province_id = @p")
.fetchObjects<Senator>("p" to 7)
}
}Content copied to clipboard
Not around the queries inside a transaction: the block then ends normally and the transaction goes on to commit. transactionResult rolls back on a returned failure instead.