It would be nice if this would support a java.time.LocalDate object:
object Person : Table("person") {
val id = integer("id").autoIncrement().primaryKey()
val name = varchar("firstName", 100)
val dateOfBirth = date("dateOfBirth")
}
Person.insert {
it[name] = "Dave Ford"
it[dateOfBirth] = LocalDate.parse("1966-10-14") //does not compile
}
It would be also nice to consider full java.time API support (instead of JodaTime)
Exposed supports java 1.6+; LocalDate is a java 1.8 api; but you can wrap a LocalDate type
@Tapac how do you think this could be done? i.e Jackson has a separate module to give java8 support.
What primitive should be used for a LocalDate or LocalDateTime ? AFAIK the only safe java.time. to support would be Instant as it maps properly to java.sql.Timestamp.
If one were to support the others regardless then I have some ideas for that:
ZonedDateTime: Deconstruct into an Instant column and a timezone varchar column. Just storing the Instant as is done now with joda DateTime is a bad API as the zone is not preserved across a store / retrieval. LocalDate, LocalTime, LocalDateTime: Convert to Instant in UTC and store in java.sql.Date, java.sql.Time, java.sql.Timestamp respectively.Our friendly neighborhood Hibernate has support for java8 time, i think we could mimic how they did the mapping to java.sql.Timestamp in each case.
Link to actual hibernate code for LocalTime. The usage of the system default timezone is a huge smell to me but it is difficult to get the full picture.
I thought about the possibility to support both JodaTime and Java Time by resolving class availability at runtime + allow to define which kind of serializer you expect to use by simple:
val jodaTimeCol = datetime<DateTime>("jodaDT")
val javaLocalTimeCol = datetime<LocalTime>("javaLocalDT")
val javaZonedLocalTimeCol = datetime<ZonedLocalTime>("javaLocalZDT")
I guess that should be possible with inline reified functions, but should check how it will affect current API.
Also, how do you think, is it needed to allow define default datetime class type to be used as reference value for old non-generified datetime("") column definition?
Please consider Java8 Instant (UTC),
e.g.: val javaInstantCol = datetime
Instant is the perfect representation of an SQL Timestamp (utc, epochmillis)
Unfortunately, LocalDateTime is widely used - but compared to Instant it just makes no sense at all.
Thanks a lot. I'm looking forward.
It seems like #184 seems like the "best" option to support this. However, in the meantime, I tried to implement a java.time.Instant backed variant of the DateCoulumnType in my own code. However, since dialects are internal it is not possible to support SQLite and the other databases without building a custom version of this library.
@plannigan why dont you just wrap the existing one and convert between joda datetime and instant?
Please note that in Java Time, LocalDate and Instant are used to represent two different concepts. The difference is explained very well in the documentation, but in short, LocalDate is suitable for birthdays, commemorative dates etc, whereas Instant represents a specific point in "universal" time such as a meeting time (across time zones).
In the case of Postgres, LocalDate would be mapped to the Date column type, whereas Instant would be mapped to TIMESTAMP WITHOUT TIME ZONE.
It would be great to see both of these supported in Exposed.
I also would prefer to use native Java 8 objects instead of having to use Joda. I鈥檇 be fine with getting an Instant out of Exposed.
Is there any update of this issue?
Is there any update of this issue?
I think not yet. Have the same issue.
Guys, do you have any news?
It will be available on the next large release (0.18.1) in both Java 8 time and JodaTime versions.
For JodaTime new localdate column type will be added
Waiting for java8 time support eagerly.
Released in 0.18.1
https://github.com/JetBrains/Exposed/wiki/LibDocumentation#exposed-0181-and-higher
Most helpful comment
It would be also nice to consider full java.time API support (instead of JodaTime)