bulkInsert

Construct a bulk insert expression in the given closure, then execute it 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 MySQL 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)
}
}

Since

2.7

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.

See also


Deprecated

ktorm-global will be removed in the future, please migrate to the standard API.

Construct a bulk insert expression in the given closure, then execute it 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 MySQL 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:

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

Return

the effected row count.

Parameters

block

the DSL block, extension function of BulkInsertStatementBuilder, used to construct the expression.

See also