比较 Rep[Option[ZonedDateTime]] 和 ZonedDateTime

Slick comparing Rep[Option[ZonedDateTime]] to ZonedDateTime

我正在尝试将 ZonedDateTime 与以下代码进行比较:

val now = ZonedDateTime.now()

val query = for {
  x <- xTable.query if x === id
  if x.starts.isAfter(now) // Doesn't work
} yield x

...slick.run(query.result)

但我似乎无法访问 .isAfter,因为 x.startsRep[Option[...]],有没有更好的方法来实现我想要实现的目标?

根据您的描述,似乎缺少合适的列类型映射。对于date/time schemas,Slick 仅支持基于JDBC 的java.sql.{Date, Time, Timestamp}。在使用 ZonedDateTime 的任何地方,您都需要在范围内使用隐式映射器。映射器应如下所示:

import java.sql.Timestamp
import java.time.ZonedDateTime
import scala.slick.driver.JdbcProfile.MappedColumnType

implicit val zonedDateTimeMapper = MappedColumnType.base[ZonedDateTime, Timestamp](
  zdt => Timestamp.from(zdt.toInstant),
  ts => ZonedDateTime.ofInstant(ts.toInstant, ZoneOffset.UTC)
)