Compile error using slick MappedColumnType for static request

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 designated table classes containing the DateTime field compile normally by importing this. However, a static query like this will not:

sql"""select s.expiresAt from tablename s limit 1""".as[DateTime].first

      

I am getting 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?

+3


source to share


2 answers


Unfortunately, you need to define another converter



implicit val getDateTimeResult = GetResult(r => new DateTime(r.nextTimestamp()))

      

+2


source


I solved it at the end using slick-joda-mapper instead of writing my own mapper.



0


source







All Articles