我正在使用Scala和Slick,我正在尝试使用两个条件执行简单查询
import JiraData._
import org.scala_tools.time.Imports._
import scala.slick.driver.PostgresDriver.simple._
val today = new DateTime()
val yesterday = today.plusDays(-1)
implicit val session = Database.forURL("jdbc:postgresql://localhost/jira-performance-manager",
driver = "org.postgresql.Driver",
user = "jira-performance-manager",
password = "jira-performance-manager").withSession {
implicit session =>
val activeUsers = users.filter(_.active === true)
for (activeUser <- activeUsers) {
val activeUserWorkogs = worklogs.filter(x => x.username === activeUser.name && x.workDate === yesterday)
}
}
但我收到错误:
Error:(20, 95) value === is not a member of scala.slick.lifted.Column[org.scala_tools.time.Imports.DateTime]
Note: implicit value session is not applicable here because it comes after the application point and it lacks an explicit result type
val activeUserWorkogs = worklogs.filter(x => x.username === activeUser.name && x.workDate === yesterday)
^
这里有什么问题?如何获得按两个条件筛选的结果列表?
答案 0 :(得分:0)
scala-tools.time使用JodaDateTime。见https://github.com/jorgeortiz85/scala-time/blob/master/src/main/scala/org/scala_tools/time/Imports.scala。 Slick没有内置的Joda支持。有Slick Joda映射器:https://github.com/tototoshi/slick-joda-mapper。或者很容易添加自己:http://slick.typesafe.com/doc/2.1.0/userdefined.html#using-custom-scalar-types-in-queries
作为旁注:类似
for (activeUser <- activeUsers) {
val activeUserWorkogs = worklogs.filter(...)
看起来像走向错误的方向。它将为每个活动用户运行另一个查询。更好的方法是使用连接或对所有活动用户的工作日志运行单个累积查询。