dave08
09/29/2021, 10:09 AMKotlinInstantColumnType
can handle an int field that stores a unix timestamp?tapac
09/30/2021, 10:45 AMdave08
09/30/2021, 11:21 AMtapac
09/30/2021, 11:29 AMdave08
09/30/2021, 11:37 AMoverride fun valueFromDB(value: Any): Instant = when (value) {
is java.sql.Timestamp -> value.toInstant().toKotlinInstant()
is String -> Instant.parse(value)
else -> valueFromDB(value.toString())
}
in my case it should reach the else... converting the int to a string, and ending up in Instant.parse... if this would be to work, there should have been an extra is Int -> Instant.fromEpochSeconds(value, 0)
... but I guess this isn't a common use-case... but it would still have been nice to have some kind of transform(fromDb: (FieldType) -> RequiredType, toDb: (RequiredType) -> FieldType)
... for this and other use-cases...val startTimestap: Instant = integer("start_at").transform({ Instant.fromEpochSeconds(it, 0) }, { it.epochSeconds })