v3.4.0
版本发布时间: 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
- PostgreSQL: support
onConflict { doNothing() }
forinsertOrUpdate
&bulkInsertOrUpdate
#255 -
PostgreSQL: Fix type mismatch error forJsonSqlType
#268 - Value semantics for Entity: add default
equals
&hashCode
function #242 - Auto transformation between JSR-310 classes and JDBC date & time #252
- Support using unsigned integers as column types #253
- Fix null-value-ignoring bug for
add
function #273