MyGit

v3.1.0

kotlin-orm/ktorm

版本发布时间: 2020-09-19 14:20:51

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

Upgrade to Kotlin 1.4

To use the new features of Kotlin, we've upgraded its version to 1.4.10, which brings some changes to us:

Entity Based Update Function

In Ktorm 3.1, we provide an update function that can update all the non-null properties of an entity object to the database. Using this function, the entity object is not required to be associated with a table first. That means, comparing to flushChanges, we don’t have to obtain an entity object from the database first before performing the update. The usage is as follows:

val employee = Employee {
    id = 5
    job = "engineer"
    salary = 100
}

database.employees.update(employee)

Generated SQL:

update t_employee set job = ?, salary = ? where id = ?

Syntax Refactoring of Insert & Update DSL

Previously, we inserted a record into the table like this:

database.insert(Employees) {
    it.name to "jerry"
    it.job to "trainee"
    it.managerId to 1
    it.hireDate to LocalDate.now()
    it.salary to 50
    it.departmentId to 1
}

Here, we used it.name to "jerry" to set the name to jerry in the closure. And the to function is a member of AssignmentsBuilder, but not the to function used to create Pair instances of Kotlin standard lib.

It is very easy for users to get confused with these two functions, so in Ktorm 3.1, we provide another set function as an alternative. The to function is marked deprecated and will be removed in the future. You can learn the new syntax here https://ktorm.liuwj.me/en/dml.html

database.insert(Employees) {
    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)
}

Other Optimizations and Bug Fixes

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

查看:2020-09-19发行的版本