kotlin-orm / ktorm

A lightweight ORM framework for Kotlin with strong-typed SQL DSL and sequence APIs.
https://www.ktorm.org
Apache License 2.0
2.13k stars 147 forks source link

Use kapt to generate boilerplate codes. #6

Open vincentlauvlwj opened 5 years ago

vincentlauvlwj commented 5 years ago

Consider introducing annotation processor tools to generate boilerplate codes like:

interface Department : Entity<Department> {
    companion object : Entity.Factory<Department>()
    val id: Int
    var name: String
    var location: String
}

open class Departments(alias: String?) : Table<Department>("t_department", alias) {
    companion object : Departments(null)
    override fun aliased(alias: String) = Departments(alias)

    val id by int("id").primaryKey().bindTo(Department::id)
    val name by varchar("name").bindTo(Department::name)
    val location by varchar("location").bindTo(Department::location)
}

It's annoying to write those companion objects and to override aliased functions...

vincentlauvlwj commented 5 years ago

Create an entity like it's a data class.

Now:

Department {
    id = 123
    name = "tect"
}

Expected:

Department(
    id = 123,
    name = "tect"
)
vincentlauvlwj commented 5 years ago

Or we can write a compiler plugin? https://www.youtube.com/watch?v=w-GMlaziIyo

godpan commented 5 years ago

这个点非常好,大大简化模板代码。

ashokgelal commented 4 years ago

Something like https://github.com/TouK/krush would be great!