bulkInsertReturning

fun <T : BaseTable<*>, C : Any> Database.bulkInsertReturning(table: T, returning: Column<C>, block: BulkInsertStatementBuilder<T>.(T) -> Unit): List<C?>(source)

Bulk insert records to the table and return the specific column's values.

Usage:

database.bulkInsertReturning(Employees, Employees.id) {
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)
}
}

Generated SQL:

insert into table (name, job, manager_id, hire_date, salary, department_id)
values (?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?)...
returning id

Since

3.4.0

Return

the returning column's values.

Parameters

table

the table to be inserted.

returning

the column to return

block

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


fun <T : BaseTable<*>, C1 : Any, C2 : Any> Database.bulkInsertReturning(table: T, returning: Pair<Column<C1>, Column<C2>>, block: BulkInsertStatementBuilder<T>.(T) -> Unit): List<Pair<C1?, C2?>>(source)

Bulk insert records to the table and return the specific columns' values.

Usage:

database.bulkInsertReturning(Employees, Pair(Employees.id, Employees.job)) {
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)
}
}

Generated SQL:

insert into table (name, job, manager_id, hire_date, salary, department_id)
values (?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?)...
returning id, job

Since

3.4.0

Return

the returning columns' values.

Parameters

table

the table to be inserted.

returning

the columns to return

block

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


fun <T : BaseTable<*>, C1 : Any, C2 : Any, C3 : Any> Database.bulkInsertReturning(table: T, returning: Triple<Column<C1>, Column<C2>, Column<C3>>, block: BulkInsertStatementBuilder<T>.(T) -> Unit): List<Triple<C1?, C2?, C3?>>(source)

Bulk insert records to the table and return the specific columns' values.

Usage:

database.bulkInsertReturning(Employees, Triple(Employees.id, Employees.job, Employees.salary)) {
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)
}
}

Generated SQL:

insert into table (name, job, manager_id, hire_date, salary, department_id)
values (?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?)...
returning id, job, salary

Since

3.4.0

Return

the returning columns' values.

Parameters

table

the table to be inserted.

returning

the columns to return

block

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