mapRow

fun <T> Flow<Result>.mapRow(f: suspend (Row) -> T): Flow<T>

Extension function for Flow that maps each row to a custom type using the provided lambda function.

Return

A Flow emitting the transformed rows for each Result.

Example usage:

val connection: Connection = // Obtain a connection from your R2DBC connection factory
val sql = "SELECT * FROM users"

connection
.query(sql)
.asRows()
.mapRow { row -> User(id = row["id"], name = row["name"], age = row["age"]) }
.collect { user -> println("User: ${user.name}, Age: ${user.age}") }

Parameters

f

A suspend function that takes a Row as input and returns an instance of type T.