insertReturning

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

Insert a record to the table and return the specific column.

Usage:

val id = database.insertReturning(Employees, Employees.id) {
set(it.id, 1)
set(it.name, "vince")
set(it.job, "engineer")
set(it.salary, 1000)
set(it.hireDate, LocalDate.now())
set(it.departmentId, 1)
}

Generated SQL:

insert into t_employee (id, name, job, salary, hire_date, department_id)
values (?, ?, ?, ?, ?, ?)
returning id

Since

3.6.0

Return

the returning column's value.

Parameters

table

the table to be inserted.

returning

the column to return

block

the DSL block used to construct the expression.


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

Insert a record to the table and return the specific columns.

Usage:

val (id, job) = database.insertReturning(Employees, Pair(Employees.id, Employees.job)) {
set(it.id, 1)
set(it.name, "vince")
set(it.job, "engineer")
set(it.salary, 1000)
set(it.hireDate, LocalDate.now())
set(it.departmentId, 1)
}

Generated SQL:

insert into t_employee (id, name, job, salary, hire_date, department_id)
values (?, ?, ?, ?, ?, ?)
returning id, job

Since

3.6.0

Return

the returning columns' values.

Parameters

table

the table to be inserted.

returning

the columns to return

block

the DSL block used to construct the expression.


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

Insert a record to the table and return the specific columns.

Usage:

val (id, job, salary) =
database.insertReturning(Employees, Triple(Employees.id, Employees.job, Employees.salary)) {
set(it.id, 1)
set(it.name, "vince")
set(it.job, "engineer")
set(it.salary, 1000)
set(it.hireDate, LocalDate.now())
set(it.departmentId, 1)
}

Generated SQL:

insert into t_employee (id, name, job, salary, hire_date, department_id)
values (?, ?, ?, ?, ?, ?)
returning id, job, salary

Since

3.6.0

Return

the returning columns' values.

Parameters

table

the table to be inserted.

returning

the columns to return

block

the DSL block used to construct the expression.