English | 简体中文

api-docs / org.ktorm.global / batchInsert

batchInsert

fun <T : BaseTable<*>> T.batchInsert(
    block: BatchInsertStatementBuilder<T>.() -> Unit
): IntArray
(source code)

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:

Employees.batchInsert {
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)
}
}

Parameters

block - the DSL block, extension function of BatchInsertStatementBuilder, used to construct the expressions.

Return
the effected row counts for each sub-operation.