withReadBackTransaction
suspend fun <T> QueryExecutor.withReadBackTransaction(block: suspend (QueryExecutor) -> Result<T>): Result<T>(source)
Runs block, a write and the read back of the row it wrote, in a single transaction: this executor itself when it is one, else one begun on it (on a connection of its own, when a pool), committed when block succeeds and rolled back when it fails.
InnoDB keeps the rows a transaction wrote locked until it ends, so no other writer can change or delete the row before it is read back. Read back after the write was committed, a concurrent writer could: a versioned update that succeeded was reported as an optimistic lock failure (the row found at another version), and an insert as having returned no row. The code generated for the MySQL and MariaDB dialects uses it, as MySQL has no RETURNING clause, and MariaDB has none for UPDATE.