MyGit

v3.4.0

kotlin-orm/ktorm

版本发布时间: 2021-05-09 23:03:16

kotlin-orm/ktorm最新发布版本:v4.1.1(2024-09-03 11:39:09)

Support Locking Clause for MySQL & PostgreSQL #247

Now Ktorm supports locking clause like for update, for share both for MySQL & PostgreSQL, for example:

val employee = database.employees
    .filter { it.name eq "vince" }
    .locking(LockingMode.FOR_UPDATE, wait = LockingWait.SKIP_LOCKED)
    .firstOrNull()

Generated SQL:

SELECT *
FROM t_employee
WHERE t_employee.name = ? 
LIMIT ?, ? 
FOR UPDATE SKIP LOCKED

Refer to these two functions for detailed usage:

Support insert ... returning ... for PostgreSQL #233

With an insert ... returning ... statement, we can insert records to the database, and at the same time, retrieve some generated columns. For example:

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

Returning multiple columns is also supported:

val (id, job) = database.insertReturning(Employees, Pair(Employees.id, Employees.job)) {
    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 (name, job, salary, hire_date, department_id) 
values (?, ?, ?, ?, ?) returning id, job

There are also some other versions of xxxReturning functions, check the API docs for details:

Other Optimizations & Bug Fixes

相关地址:原始地址 下载(tar) 下载(zip)

查看:2021-05-09发行的版本