I use the following in my code, which might also work for you:
import java.sql.Timestamp
import org.joda.time.DateTime
import org.joda.time.DateTimeZone.UTC
import scala.slick.lifted.MappedTypeMapper.base
import scala.slick.lifted.TypeMapper
implicit val DateTimeMapper: TypeMapper[DateTime] =
base[DateTime, Timestamp](
d => new Timestamp(d millis),
t => new DateTime(t getTime, UTC))
Edit (after your edit =^.~= ): (a bit late but I hope it still helps)
Ah, OK, since you're not using lifted embedding, you'll have to define different implicit values (as indicated by the error message from the compiler). Something like the following should work (though I haven't tried myself):
implicit val SetDateTime: SetParameter[DateTime] = new SetParameter {
def apply(d: DateTime, p: PositionedParameters): Unit =
p setTimestamp (new Timestamp(d millis))
}
For the other way round (retrieving the results of the SELECT
), it looks like you'd need to define a GetResult
:
implicit val GetDateTime: GetResult[DateTime] = new GetResult {
def apply(r: PositionedResult) = new DateTime(r.nextTimestamp getTime, UTC))
}
So, basically this is just the same as with the lifted embedding, just encoded with different types.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…