简体   繁体   English

将Rep [Option [ZonedDateTime]]与ZonedDateTime进行比较

[英]Slick comparing Rep[Option[ZonedDateTime]] to ZonedDateTime

I'm trying to compare ZonedDateTime with following code: 我正在尝试将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)

But it seems that I can't access .isAfter because x.starts is Rep[Option[...]] , is there a better way to do what I'm trying to achieve? 但是似乎我无法访问.isAfter因为x.startsRep[Option[...]] ,是否有更好的方法来完成我要实现的目标?

From what you've described, it sounds like a suitable column type mapping might be missing. 根据您的描述,听起来可能缺少合适的列类型映射。 For date/time schemas , Slick only supports JDBC-based java.sql.{Date, Time, Timestamp} . 对于日期/时间架构 ,Slick仅支持基于JDBC的java.sql.{Date, Time, Timestamp} You would need an implicit mapper in scope wherever ZonedDateTime is used. 无论ZonedDateTime使用ZonedDateTime您都需要一个隐式映射器。 The mapper should look something like below: 映射器应如下所示:

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)
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM