← Back to Stormify Documentation

withConnection

suspend fun <R> withConnection(block: suspend () -> R): R

Borrows a pooled connection for the duration of block, without starting a transaction. The connection stays in auto-commit mode; every statement inside commits independently.

If called inside another withConnection { } or transaction { } on the same SuspendStormify, reuses that scope's connection (auto-commit is never touched).

Exception contract: whatever block throws propagates to the caller unchanged — unlike transaction, no SQLException wrapping happens on this path. Application-level exceptions (validation, not-found, constraint violations in auto-commit) do not harm the borrowed connection; it is returned to the pool and reused. Only coroutine cancellation evicts it.