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 your import 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 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

    • βž• 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>>) to json<List<Int>>("foo").