Skip to content

Provide DslMapper To simplify Kotlin code #1021

@huicunjun

Description

@huicunjun

Provide DslMapper
To simplify Kotlin code

Refer to the exposed https://github.com/JetBrains/Exposed

   class PersonTable : SqlTable("Person") {
        val id = column<Int>(name = "id", jdbcType = JDBCType.INTEGER, javaProperty = "id")
        val firstName = column<String>(name = "first_name", jdbcType = JDBCType.VARCHAR, javaProperty = "firstName")
        val lastName = column<LastName>(
            name = "last_name",
            jdbcType = JDBCType.VARCHAR,
            typeHandler = "examples.kotlin.mybatis3.canonical.LastNameTypeHandler",
            javaProperty = "lastName"
        )
        val birthDate = column<Date>(name = "birth_date", jdbcType = JDBCType.DATE, javaProperty = "birthDate")
        val employed = column<Boolean>(
            name = "employed",
            JDBCType.VARCHAR,
            typeHandler = "examples.kotlin.mybatis3.canonical.YesNoTypeHandler",
            javaProperty = "employed"
        )
        val occupation = column<String>(name = "occupation", jdbcType = JDBCType.VARCHAR, javaProperty = "occupation")
        val addressId = column<Int>(name = "address_id", jdbcType = JDBCType.INTEGER, javaProperty = "addressId")
    }

interface DslMapper <Table,Entiy>{
}


@Mapper
interface PersonMapper :  DslMapper<PersonTable,PersonRecord>{}



val personMapper:PersonMapper

personMapper.insert{
 it[PersonTable.lastName] = "hello"
}

personMapper.insert(PersonRecord(100, "Joe", LastName("Jones"), Date(), true, "Developer", 1))

personMapper.delete{
 it[PersonTable.id] = 1
}

personMapper.updateById(PersonRecord(100, "Joe", LastName("Jones"), Date(), true, "Developer", 1))
personMapper.update(where = { PersonTable.id eq "alex" }) {
            it[name] = "Alexey"
  }


Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions