I run into problem when using Quill
's infix operation .
Scala
2.12.4 Quill
2.3.3
import io.getquill._
val ctx = new SqlMirrorContext(PostgresDialect, SnakeCase)
import ctx._
// infix for custom DB operation
implicit class StringQuotes(left: String) {
def equalTest(right: String): Quoted[Boolean] = quote {
infix"$left = $right".as[Boolean]
}
}
case class User(name: String)
object User {
// normal usage
def filter1() = quote {
query[User]
.filter(
user => user.name == "Cool"
)
}
//using infix for custom operation
def filter2() = quote {
query[User]
.filter(
user => user.name equalTest "Cool"
)
}
}
//pass, and generates a valid SQL.
ctx.run(User.filter1())
// fail
ctx.run(User.filter2())
The error message is obscure:
java.util.NoSuchElementException: value user
..... too long to show
Error while emitting main.scala
It only indicate filter2
is cause, and doesn't say which line wrong.
Runnable code snippet at Scastie
online editor https://scastie.scala-lang.org/superChing/haYVkGLDSlKsOhYlaPdO1w
It works without explicit return type Quoted[Boolean]
in equalTest
function :
def equalTest(right: String) = quote {
infix"$left = $right".as[Boolean]
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.