Column and Table Naming
Using @SerialName, @ExoEntity, and @ExoField annotations
If you need your table or columns to be named differently that than the data-class name or itβs fields you can use the kotlinx.serialization SerialName("...") annotation:
@SerialName("corp_customer")
data class CorpCustomer {
val name: String
@SerialName("num_orders")
val numOrders: Int
@SerialName("created_at")
val createdAt: Int
}
val q = sql { Table<CorpCustomer>() }
q.buildFor.Postgres().runOn(myDatabase)
//>
If you do not want to use this annotation for somemthing else (e.g. JSON field names) you can also use @ExoEntity and @ExoField to do the same thing.
@ExoEntity("corp_customer")
data class CorpCustomer {
val name: String
@ExoField("num_orders")
val numOrders: Int
@ExoField("created_at")
val createdAt: Int
}
val q = sql { Table<CorpCustomer>() }
q.buildFor.Postgres().runOn(myDatabase)
//> SELECT x.name, x.num_orders, x.created_at FROM corp_customer x