Hi, This is my day1 with Exposed API. How to use a...
# exposed
m
Hi, This is my day1 with Exposed API. How to use a table that has a char(3) column as primary key. How to define an Entity or data class called CountryCode? How do I load all country codes into a ListCountryCode? please advise
Copy code
object CountryCodes : Table() {
    override val tableName = "country_codes"
    val code = varchar("code", 3).isNotNull()
    val countryName = varchar("country_name", 100).isNotNull()
    val sortOrder = integer("sort_order").isNotNull()
    val displaySortOrder = integer("display_sort_order").isNotNull()
    // override val primaryKey = PrimaryKey(code,name="pk_country_codes")
}
a
> How to use a table that has a char(3) column as primary key?
Copy code
object CountryCodes: Table() {
    val code = char("id", 3)
    override val primaryKey = PrimaryKey(code)
}
How to define an Entity or data class called CountryCode?
Copy code
data class CountryCode(val code: String)
How do I load all country codes into a List<CountryCode>?
Copy code
val codes = CountryCodes.selectAll().map { CountryCode(it[CountryCodes.code]) }
For more information please read the official documentation.
m
Thank you!