batchInsert
fun <T : BaseTable<*>> Database.batchInsert(table: T, block: BatchInsertStatementBuilder<T>.() -> Unit): IntArray(source)
Construct insert expressions in the given closure, then batch execute them and return the effected row counts for each expression.
Note that this function is implemented based on Statement.addBatch and Statement.executeBatch, and any item in a batch operation must have the same structure, otherwise an exception will be thrown.
Usage:
database.batchInsert(Employees) {
item {
set(it.name, "jerry")
set(it.job, "trainee")
set(it.managerId, 1)
set(it.hireDate, LocalDate.now())
set(it.salary, 50)
set(it.departmentId, 1)
}
item {
set(it.name, "linda")
set(it.job, "assistant")
set(it.managerId, 3)
set(it.hireDate, LocalDate.now())
set(it.salary, 100)
set(it.departmentId, 2)
}
}
Content copied to clipboard
Since
2.7
Return
the effected row counts for each sub-operation.
Parameters
table
the table to be inserted.
block
the DSL block, extension function of BatchInsertStatementBuilder, used to construct the expressions.