querySingleValue
fun <T> querySingleValue(jdbcConnectionFactory: JdbcConnectionFactory, query: String, bindParameters: (PreparedStatement) -> Unit? = null, withResultSet: (ResultSet) -> T, noResultsCase: () -> Unit = throwNoResultsIllegalState, multipleResultsCase: () -> Unit = throwMultipleResultsIllegalState): T
Convenience function for executing a query that is expected to return exactly one row and extracting a single value from that row.
Return
The value extracted from the single result row using the withRS function
Parameters
jdbcConnectionFactory
Factory for creating JDBC connections
query
SQL query string to execute (should return exactly one row)
bindParameters
Optional lambda to bind parameters to the PreparedStatement before execution
withResultSet
Lambda function to process the ResultSet and extract the desired value
noResultsCase
Lambda to execute if the query returns no results
multipleResultsCase
Lambda to execute if the query returns multiple results