I foundout that scalaquery uses java.sql.date as the date object. But it drops time when I create java.sql.date.
Is there any way that I can use to create mysql datetime field in scalaquery?
I foundout that scalaquery uses java.sql.date as the date object. But it drops time when I create java.sql.date.
Is there any way that I can use to create mysql datetime field in scalaquery?
There is no java.util.Date
support in ScalaQuery. However, it's possible to enhance ScalaQuery with your own type mappers. For java.util.Date
such a wrapper could look like this
implicit val JavaUtilDateTypeMapper = MappedTypeMapper.base[java.util.Date, Long] (_.getTime, new java.util.Date(_))
converting the java.util.Date
into a simple Long. It depends on your database what's the best target, in my case a Long works perfectly.
Instead of using java.sql.Date
, try using java.sql.Timestamp
, when declaring the column.
It looks like that yields a better mapping for a column with both date and time elements.