Open mwisnicki opened 1 month ago
BTW using instantType works pretty well:
import slick.jdbc.{GetResult, PositionedResult, PostgresProfile, SetParameter}
import java.time.Instant
trait PlainMappers {
import PostgresProfile.columnTypes.instantType
private def toInstant(unused: String, pr: PositionedResult) = instantType.getValue(pr.rs, pr.currentPos)
implicit val getResultInstant: GetResult[Instant] = pr => toInstant(pr.nextString(), pr)
implicit val getResultInstantOpt: GetResult[Option[Instant]] = pr => pr.nextStringOption().map(toInstant(_, pr))
implicit val setParameterInstant: SetParameter[Instant] = (v, pp) => {
val npos = pp.pos + 1
instantType.setValue(v, pp.ps, npos)
pp.pos = npos
}
implicit val setParameterInstantOption: SetParameter[Option[Instant]] = (v, pp) => {
val npos = pp.pos + 1
v match {
case None => pp.ps.setNull(npos, java.sql.Types.TIMESTAMP)
case Some(value) => instantType.setValue(value, pp.ps, npos)
}
pp.pos = npos
}
}
Add this test case:
to https://github.com/tminglei/slick-pg/blob/master/src/test/scala/com/github/tminglei/slickpg/PgDate2SupportSuite.scala#L434
And it will fail: