github kotlin-orm/ktorm v3.4.0

latest releases: v4.1.1, v4.1.0, v4.0.0...
3 years ago

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() } for insertOrUpdate & bulkInsertOrUpdate #255
  • PostgreSQL: Fix type mismatch error for JsonSqlType #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

Don't miss a new ktorm release

NewReleases is sending notifications on new releases.