Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compile error using slick MappedColumnType for static query

Tags:

scala

slick

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?

like image 904
Tom Haigh Avatar asked Nov 27 '25 04:11

Tom Haigh


1 Answers

Unfortunately you need to define another converter

implicit val getDateTimeResult = GetResult(r => new DateTime(r.nextTimestamp()))
like image 193
expert Avatar answered Nov 28 '25 19:11

expert



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!