bulkInsert
fun <T : BaseTable<*>> Database.bulkInsert(table: T, block: BulkInsertStatementBuilder<T>.(T) -> Unit): Int(source)
Bulk insert records to the table and return the effected row count.
The usage is almost the same as batchInsert, but this function is implemented by generating a special SQL using SQLite bulk insert syntax, instead of based on JDBC batch operations. For this reason, its performance is much better than batchInsert.
The generated SQL is like: insert into table (column1, column2) values (?, ?), (?, ?), (?, ?)...
.
Usage:
database.bulkInsert(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
Return
the effected row count.
Parameters
table
the table to be inserted.
block
the DSL block, extension function of BulkInsertStatementBuilder, used to construct the expression.