MyGit

v2.6

kotlin-orm/ktorm

版本发布时间: 2019-11-02 21:19:54

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

Support Running on Android Devices (#22)

Now, Ktorm is available for Android SQLite with the support of SQLDroid driver. And technically, any other JDBC driver is also supported (if you really need them running on Android).

Update JVM Target to 1.6

For maximum compatibility, we updated the compiler option -jvm-target to 1.6. This option is used to specify the version of the generated JVM bytecode. Moreover, to support running on Android and JDK 1.6, we added three SqlType implementations, they supports java.sql.Timestamp, java.sql.Date and java.sql.Time, because JSR-310 is not available on those platforms.

Support Multiple Bindings on One Column

Now, we can bind a column to multiple properties by calling the bindTo or references functions continuously. In this way, when an entity object is retrieved from the database, the value of this column will be filled to each property it binds.

interface Config : Entity<Config> {
    val key: String
    var value1: String
    var value2: String
}

object Configs : Table<Config>("t_config") {
    val key by varchar("key").primaryKey().bindTo { it.key }
    val value by varchar("value").bindTo { it.value1 }.bindTo { it.value2 }
}

In the example above, we bound the value column to both value1 and value2, so the values of these two properties would be the same in an entity object obtained from the database.

Please note that multiple bindings are only available for query operations. When we are inserting or updating an entity, the first binding will prevail, and other bindings will be ignored.

Support Column Alias DSL (by @waluo, #37)

Now, we can assign aliases to the selected columns of a query and use them in subsequent clauses such as group by and having, just like the as keyword in SQL. Here is an example. This query selects departments whose average salary is greater than 100, then returns the average salaries along with their department’s IDs.

val deptId = Employees.departmentId.aliased("dept_id")
val salaryAvg = avg(Employees.salary).aliased("salary_avg")

Employees
    .select(deptId, salaryAvg)
    .groupBy(deptId)
    .having { salaryAvg greater 100.0 }
    .forEach { row ->
        println("${row[deptId]}:${row[salaryAvg]}")
    }

Generated SQL:

select t_employee.department_id as dept_id, avg(t_employee.salary) as salary_avg 
from t_employee 
group by dept_id 
having salary_avg > ?

Other Optimizations and Bug Fixes

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

查看:2019-11-02发行的版本