https://kotlinlang.org logo
#exposed
Title
# exposed
m

Manas Marthi

11/26/2023, 1:31 PM
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

Aleksei Tirman [JB]

11/27/2023, 11:21 AM
> 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

Manas Marthi

11/29/2023, 6:37 PM
Thank you!