Is there a less boilerplate way to use exposed?
Currently I do the structure and migration with flyway. I create a table in the .sql file.
Copy code
CREATE TABLE tts_schedule (
scheduleId INT NOT NULL PRIMARY KEY,
companyId VARCHAR(160) NOT NULL
);
Then I have to write a representation:
Copy code
object ScheduleTable : Table("tts_schedule") {
val scheduleId = integer("scheduleId")
val companyId = varchar("companyId", 160)
override val primaryKey = PrimaryKey(scheduleId)
}
Then the insert, update, delete and get transactions.
And then a
ResultsRow
extension function to map the result values to a DTO.
Is there a better way?
r
Ruben Holen
09/06/2023, 12:04 PM
Copy code
object ScheduleTable : IntIdTable("tts_schedule", "scheduleId") {
val companyId = varchar("companyId", 160)
}
class Schedule(id: EntityID<Int>) : IntEntity(id) {
companion object : IntEntityClass<Schedule>(ScheduleTable)
val companyId by ScheduleTable.companyId
}
Ruben Holen
09/06/2023, 12:06 PM
Also look into
SchemaUtils.createMissingTablesAndColumns()
if you don't want to write the sql by hand
h
Hildebrandt Tobias
09/06/2023, 12:26 PM
Thank you for the answers. The class definition is definitely helpful!
A quick search tells me that there is no good way of handling migrations directly in exposed.
So I will still need to maintain the structure in sql, which is not so bad.