scala 比较ZIO Quill中的ZonedDateTime

guykilcj  于 2023-10-18  发布在  Scala
关注(0)|答案(1)|浏览(105)

我尝试使用>基于ZonedDateTime进行筛选时出现错误。使用==
我用的是Scala 3.2.0和Quill 4.6.0。
它似乎应该工作的基础上,羽毛笔。会少了什么呢?

case class Post(id: Long, createdAt: ZonedDateTime)

import io.getquill.*
import io.getquill.extras.ZonedDateTimeOps

def getUpdated(since: ZonedDateTime): Task[List[Post]] = {
    run {
      query[Post]
        .filter(_.createdAt > lift(since))
    }
      .provideEnvironment(ZEnvironment(dataSource))
  }

我收到以下错误消息。

[error]    |s"==== Tree cannot be parsed to 'Ast' ====
[error]    |  ZonedDateTimeOps(_$7.createdAt)
[error]    |==== Extractors ===
[error]    |  Apply(Ident("ZonedDateTimeOps"), List(Select(Ident("_$7"), "createdAt")))
[error]    |==== Stacktrace ===
[error]    |  java.base/java.lang.Thread.getStackTrace(Thread.java:1610)
[error]    |  io.getquill.parser.engine.failParse$.apply(failParse.scala:27)
[error]    |  io.getquill.parser.engine.failParse$.apply(failParse.scala:12)
[error]    |  io.getquill.parser.engine.Parser.error(Parser.scala:10)
[error]    |  io.getquill.parser.engine.Parser.error$(Parser.scala:7)
[error]    |  io.getquill.parser.engine.ParserChain$$anon$1.error(ParserChain.scala:15)
[error]    |  io.getquill.parser.engine.Parser.apply$$anonfun$1(Parser.scala:9)
[error]    |  scala.Option.getOrElse(Option.scala:201)
[error]    |  io.getquill.parser.engine.Parser.apply(Parser.scala:9)
[error]    |  io.getquill.parser.engine.Parser.apply$(Parser.scala:7)
[error]    |  io.getquill.parser.engine.ParserChain$$anon$1.apply(ParserChain.scala:15)
[error]    |  io.getquill.parser.OperationsParser$$anon$20.applyOrElse(Parser.scala:889)
[error]    |  io.getquill.parser.OperationsParser$$anon$20.applyOrElse(Parser.scala:875)
[error]    |  scala.PartialFunction$Lifted.apply(PartialFunction.scala:313)
[error]    |  scala.PartialFunction$Lifted.apply(PartialFunction.scala:309)
[error]    |  io.getquill.parser.engine.ParserChain$.io$getquill$parser$engine$ParserChain$OrElse$$anon$2$$_$$anonfun$1$$anonfun$1(ParserChain.scala:43)
[error]    |  scala.Option.orElse(Option.scala:477)
[error]    |  io.getquill.parser.engine.ParserChain$OrElse$$anon$2.$anonfun$1(ParserChain.scala:43)
[error]    |  scala.PartialFunction$$anonfun$fromFunction$1.applyOrElse(PartialFunction.scala:338)
[error]    |  scala.runtime.AbstractPartialFunction.apply(AbstractPartialFunction.scala:35)
[error]    |  io.getquill.parser.engine.ParserChain$OrElse$$anon$2.$anonfun$1(ParserChain.scala:43)
[error]    |  scala.PartialFunction$$anonfun$fromFunction$1.applyOrElse(PartialFunction.scala:338)
[error]    |  scala.runtime.AbstractPartialFunction.apply(AbstractPartialFunction.scala:35)
[error]    |  io.getquill.parser.engine.ParserChain$OrElse$$anon$2.$anonfun$1(ParserChain.scala:43)
[error]    |  scala.PartialFunction$$anonfun$fromFunction$1.applyOrElse(PartialFunction.scala:338)
[error]    |  scala.runtime.AbstractPartialFunction.apply(AbstractPartialFunction.scala:35)
[error]    |  io.getquill.parser.engine.ParserChain$OrElse$$anon$2.$anonfun$1(ParserChain.scala:43)
[error]    |  scala.PartialFunction$$anonfun$fromFunction$1.applyOrElse(PartialFunction.scala:338)
[error]    |  scala.runtime.AbstractPartialFunction.apply(AbstractPartialFunction.scala:35)
[error]    |  io.getquill.parser.engine.ParserChain$OrElse$$anon$2.$anonfun$1(ParserChain.scala:43)
[error]    |  scala.PartialFunction$$anonfun$fromFunction$1.applyOrElse(PartialFunction.scala:338)
[error]    |  scala.runtime.AbstractPartialFunction.apply(AbstractPartialFunction.scala:35)
[error]    |  io.getquill.parser.engine.ParserChain$OrElse$$anon$2.$anonfun$1(ParserChain.scala:43)
[error]    |  scala.PartialFunction$$anonfun$fromFunction$1.applyOrElse(PartialFunction.scala:338)
[error]    |  scala.runtime.AbstractPartialFunction.apply(AbstractPartialFunction.scala:35)
[error]    |  io.getquill.parser.engine.Parser.apply(Parser.scala:9)
[error]    |  io.getquill.parser.engine.Parser.apply$(Parser.scala:7)
[error]    |  io.getquill.parser.engine.ParserChain$$anon$1.apply(ParserChain.scala:15)
[error]    |  io.getquill.parser.QueryParser$$anon$13.applyOrElse(Parser.scala:540)
[error]    |  io.getquill.parser.QueryParser$$anon$13.applyOrElse(Parser.scala:520)
[error]    |  scala.PartialFunction$Lifted.apply(PartialFunction.scala:313)
[error]    |  scala.PartialFunction$Lifted.apply(PartialFunction.scala:309)
[error]    |  io.getquill.parser.engine.ParserChain$.io$getquill$parser$engine$ParserChain$OrElse$$anon$2$$_$$anonfun$1$$anonfun$1(ParserChain.scala:43)
[error]    |  scala.Option.orElse(Option.scala:477)
[error]    |  io.getquill.parser.engine.ParserChain$OrElse$$anon$2.$anonfun$1(ParserChain.scala:43)
[error]    |  scala.PartialFunction$$anonfun$fromFunction$1.applyOrElse(PartialFunction.scala:338)
[error]    |  scala.runtime.AbstractPartialFunction.apply(AbstractPartialFunction.scala:35)
[error]    |  io.getquill.parser.engine.ParserChain$OrElse$$anon$2.$anonfun$1(ParserChain.scala:43)
[error]    |  scala.PartialFunction$$anonfun$fromFunction$1.applyOrElse(PartialFunction.scala:338)
[error]    |  scala.runtime.AbstractPartialFunction.apply(AbstractPartialFunction.scala:35)
qyzbxkaa

qyzbxkaa1#

我不知道你是否已经解决了这个问题,但在这里回答后代。
显然,你必须定义自己的内联比较函数,像这样:

extension (inline date: ZonedDateTime)
    inline def >(inline other: ZonedDateTime) = quote { sql"$date > $other".as[Boolean] }
    inline def <(inline other: ZonedDateTime) = quote { sql"$date < $other".as[Boolean] }

参见:https://github.com/zio/zio-protoquill/issues/208

相关问题