I have the following mapper so that I can use Joda DateTime values in my Slick models and queries:
import java.sql.Timestamp
import org.joda.time.DateTime
import scala.slick.driver.MySQLDriver.simple._
object Mappers {
implicit def joda =
MappedColumnType.base[DateTime, Timestamp](
dt => new Timestamp(dt.getMillis),
ts => new DateTime(ts.getTime)
)
}
The table classes that I have defined containing a DateTime field appear to compile fine by importing this. However a static query like this will not:
sql"""select s.expiresAt from tablename s limit 1""".as[DateTime].first
I get this error:
could not find implicit value for parameter rconv: scala.slick.jdbc.GetResult[org.joda.time.DateTime]
What do I need to add to make this work?
Unfortunately you need to define another converter
implicit val getDateTimeResult = GetResult(r => new DateTime(r.nextTimestamp()))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With