Skip to content

Commit

Permalink
(#4) Allowing nullable params for batchExecuteCommand (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
bhimsenp authored Mar 16, 2020
1 parent ede1c41 commit 39bed06
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions runtime/src/main/kotlin/norm/SqlExtensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ fun ResultSet.toTable(columnNames: List<String> = getColumnNames()): List<List<A

// TODO - handle prepareStatements Failure as well

fun PreparedStatement.withParams(params: List<Any> = listOf()): PreparedStatement =
fun PreparedStatement.withParams(params: List<Any?> = listOf()): PreparedStatement =
this.also { self ->
params.forEachIndexed { index, param -> self.setObject(index + 1, param) }
}

fun PreparedStatement.withBatches(batchedParams: List<List<Any>> = listOf()) =
fun PreparedStatement.withBatches(batchedParams: List<List<Any?>> = listOf()) =
this.also { ps ->
batchedParams.forEach { params ->
ps.withParams(params).addBatch()
Expand All @@ -52,7 +52,7 @@ fun Connection.executeCommand(sql: String, params: List<Any> = listOf()): Int =
.withParams(params)
.use { it.executeUpdate() } // auto-close ps

fun Connection.batchExecuteCommand(sql: String, batchedParams: List<List<Any>> = listOf()): List<Int> =
fun Connection.batchExecuteCommand(sql: String, batchedParams: List<List<Any?>> = listOf()): List<Int> =
this.prepareStatement(sql)
.withBatches(batchedParams)
.use { it.executeBatch() }
Expand Down

0 comments on commit 39bed06

Please sign in to comment.