execQuery

suspend fun <R> execQuery(query: SuspendExecutable<ResultApi, *>, body: suspend Statement<ResultApi>.(R2dbcResult) -> R): R?

Executes the provided query object, retrieves the generated result wrapped as a R2dbcResult, then calls the specified function body with this generated value as its argument and returns its result.

This function also updates its calling R2dbcTransaction instance's statement count and overall duration, as well as whether the execution time for query exceeds the threshold set by DatabaseConfig.warnLongQueriesDuration. If Transaction.debug is set to true, these tracked values are stored for each call in Transaction.statementStats.

val allCompleteTasks = Tasks.selectAll().where { Tasks.isComplete eq true }

val completeTitles = execQuery(allCompleteTasks) {
it.mapRows { row ->
row.origin.get("title")
}
.mapNotNull(Any?::toString)
.toList()
}

Return

The result of calling body on the R2dbcResult generated by the query execution, or null if no result was returned by the database.

Parameters

query

An executable statement that is expected to potentially returns results. This includes instances of the Query class as well as executables defined using explain or any of the extension functions like insertReturning or updateReturning.