Peter Scardera
12/10/2021, 4:41 PMdave08
12/12/2021, 3:44 AMhfhbd
12/15/2021, 11:41 AM// Custom implementation since Exposed kotlin-datetime timestamp does not use UTC...
public fun Table.instant(name: String): Column<Instant> =
registerColumn(name = name, type = PostgresInstantColumn())
private class PostgresInstantColumn : ColumnType(), IDateColumnType {
override val hasTimePart = true
override fun sqlType(): String = "TIMESTAMPTZ"
override fun valueFromDB(value: Any): Instant = when (value) {
is Instant -> value
is java.time.Instant -> value.toKotlinInstant()
is java.sql.Timestamp -> value.toInstant().toKotlinInstant()
is String -> value.toInstant()
else -> error("Unexpected value of type Instant: $value of ${value::class.qualifiedName}")
}
override fun notNullValueToDB(value: Any): java.sql.Timestamp = when (value) {
is Instant -> java.sql.Timestamp.from(value.toJavaInstant())
is java.time.Instant -> java.sql.Timestamp.from(value)
is String -> java.sql.Timestamp.from(value.toInstant().toJavaInstant())
else -> error("Unexpected value of type Instant: $value of ${value::class.qualifiedName}")
}
}
Peter Scardera
12/15/2021, 3:47 PM