JetBrains / Exposed

Kotlin SQL Framework
http://jetbrains.github.io/Exposed/
Apache License 2.0
8.28k stars 690 forks source link

fix: EXPOSED-384 CurrentTimestamp cannot be used with OffsetDateTimeColumnType #2081

Closed bog-walk closed 4 months ago

bog-walk commented 4 months ago

Version 0.50.0 introduced 2 changes to CurrentTimestamp:

So its previous use as a default expression with a timezone compatible column is no longer possible, as even changing to a singleton still requirs OffsetDateTime as the return type:

// compile error - invoke() not found
val t3: Column<OffsetDateTime> = timestampWithTimeZone("t3").defaultExpression(CurrentTimestamp())

// compile error - type mismatch
val t3: Column<OffsetDateTime> = timestampWithTimeZone("t3").defaultExpression(CurrentTimestamp)

This fix introduces a new object CurrentTimestampWithTimeZone for this specific use, to both modules exposed-java-time and exposed-kotlin-datetime.

Rather than repeating the same query builder logic, the 3 CurrentX objects now extend from a base sealed class.

Note: A new object was not added to exposed-joda-time since timestampWithTimeZone() use the same DateTime column type, so it can be used with CurrentDateTime.