【发布时间】:2014-05-26 20:42:20
【问题描述】:
我使用 slick 2.0.2,我只想做一个简单的过滤器或使用 where 子语句,我只想在过滤器中执行“and”、“or”和“not”之类的逻辑操作:
val subjectdata = TableQuery[SubjectTable]
...
subjectdata.where(i=>(i.id===id && i.userId===rs.user.get.identityId.userId)).list()
并得到错误:
[error] G:\testprojects\slickplay\app\controllers\ShopController.scala:89: Cannot perform option-mapped operation
[error] with type: (Long, String) => R
[error] for base type: (Long, Long) => Boolean
[error] subjectdata.where(i=>(i.id===id && i.userId===rs.user.get.identityId
.userId)).list()
[error]
^
在 slick 1.0.1 中我可以做到:
val results = Query(TableClass)
.filter(r => r.isNull || r.expires > new Timestamp(DateTime.now().getMillis()))
.list
我想在 Slick2 中的 TableQuery 上做类似的事情。怎么做?
【问题讨论】:
-
在不知道
i.id、i.userId和rs.user.get.identifyId的情况下,很难猜出可能是什么问题。 -
另外,你在比较两个完全不同的东西。
-
@pedrofurla rs.user.get.identifyId 无关紧要,只是将其视为常量。问题是如何在这里使用和不使用这个逻辑运算符。
-
@user504909 - 编译器报告了一个类型问题,这是 Scala 真正擅长的。特别是,看起来
i.id的类型与id的类型不同,或者i.userId的类型与rs.user.get.identityId的类型不同。
标签: scala slick logical-operators slick-2.0