singleUpdate
Executes a single SQL update using a JDBC connection.
This function takes an SQL statement sql and an optional prepare function, which prepares the statement before execution.
Return
A Flow of the number of rows affected by the update.
Example:
val jdbc: Jdbc = ...
val sql = "UPDATE users SET active = 1 WHERE id = 42"
jdbc.singleUpdate(sql)
.collect { rowsAffected ->
println("Rows affected: $rowsAffected")
}
Parameters
The SQL statement to execute.
A suspend function that prepares the statement before execution.
Executes a single SQL update using a JDBC connection for each item in the upstream flow.
This function takes an SQL statement sql, an upstream flow, concurrency, and an optional prepare function, which prepares the statement before execution.
Return
A Flow of the number of rows affected by the update for each item.
Example:
val jdbc: Jdbc = ...
val sql = "UPDATE users SET active = 1 WHERE id = ?"
val userIds = flowOf(1, 2, 3, 4, 5)
jdbc.singleUpdate(sql, userIds, prepare = { id ->
setInt(1, id)
}).collect { rowsAffected ->
println("Rows affected: $rowsAffected")
}
Parameters
The SQL statement to execute.
A Flow of items to process.
The level of concurrency for executing the updates.
A suspend function that prepares the statement for each item before execution.