```class InstantFromEpochSecondsColumnType : Colum...
# exposed
d
Copy code
class InstantFromEpochSecondsColumnType : ColumnType() {
    override fun sqlType(): String = currentDialect.dataTypeProvider.integerType()
    override fun valueFromDB(value: Any): Instant = when (value) {
        is Int -> Instant.fromEpochSeconds(value.toLong(), 0)
        is Number -> Instant.fromEpochSeconds(value.toLong(), 0)
        is String -> Instant.fromEpochSeconds(value.toLong(), 0)
        else -> error("Unexpected value of type Int: $value of ${value::class.qualifiedName}")
    }

    override fun notNullValueToDB(value: Any): Any = when {
        value is Instant -> value.epochSeconds
        else -> error("Invalid value $value")
    }
}

fun Table.timestampFromEpochSeconds(name: String): Column<Instant> = registerColumn(name, InstantFromEpochSecondsColumnType())