Ktorm v3.2.0 Release Notes
Release Date: 2020-10-08 // about 4 years ago-
π¦ Package Name Changed to org.ktorm
Finally, we have our own domain and the official website becomes https://www.ktorm.org
Accordingly, starting from Ktorm 3.2, we have changed our group ID to
org.ktorm
, so you need to modify your Maven dependency:\<dependency\> \<groupId\>org.ktorm\</groupId\> \<artifactId\>ktorm-core\</artifactId\> \<version\>3.2.0\</version\> \</dependency\>
Or Gradle:
compile "org.ktorm:ktorm-core:3.2.0"
π¦ Package names are also changed to
org.ktorm.*
, so you also need to modify yourimport
statements:import org.ktorm.database.\*import org.ktorm.dsl.\*import org.ktorm.entity.\*import org.ktorm.schema.\*
With the only two steps, you have completed all the migration work to version 3.2. Everything should work well as there are no other changes apart from this.
Previous changes from v3.1.0
-
β¬οΈ 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:
Explicit API mode to ensure we don't expose some internal things accidentally.
π Contract support for
database.useConnection { .. }
&database.useTransaction { .. }
to let the compiler know our callback functions are called in place exactly once.π Deprecation of
mapColumnsN
&aggregateColumnsN
functions. As Kotlin 1.4 supports overload resolution by lambda return type, we don't need these functions anymore,mapColumns
&aggregateColumns
is enough.database.employees .filter { it.departmentId eq 1 } .mapColumns { tupleOf(it.id, it.name) } .forEach { (id, name) -\>println("$id:$name") }
β‘οΈ 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 toflushChanges
, 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 theto
function is a member ofAssignmentsBuilder
, but not theto
function used to createPair
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. Theto
function is marked deprecated and will be removed in the future. You can learn the new syntax here https://ktorm.liuwj.me/en/dml.htmldatabase.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
- β Add
ShortSqlType
. #160 - β Add MySQL
IF
function. #163 - π Support mixed-case column names & auto case transform. #175
- π Allow specify PostgreSQL
insertOrUpdate
conflict columns. #181 - π Support
select .. for update
. #69 - π Support catalog & schema in table definition. #89, #154, #183
- Check max column name length. #122
- π Fix timestamp fraction bug. #130
- β‘οΈ Update the syntax of defining JSON columns from
json("foo", typeRef<List<Int>>)
tojson<List<Int>>("foo")
.
- β Add