ktorm icon indicating copy to clipboard operation
ktorm copied to clipboard

Use kapt to generate boilerplate codes.

Open vincentlauvlwj opened this issue 6 years ago • 4 comments

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 avatar Jan 05 '19 07:01 vincentlauvlwj

Create an entity like it's a data class.

Now:

Department {
    id = 123
    name = "tect"
}

Expected:

Department(
    id = 123,
    name = "tect"
)

vincentlauvlwj avatar Jan 10 '19 09:01 vincentlauvlwj

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

vincentlauvlwj avatar Apr 12 '19 02:04 vincentlauvlwj

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

godpan avatar Jul 19 '19 10:07 godpan

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

ashokgelal avatar Jan 05 '20 17:01 ashokgelal