我一直在尝试通过Slick 3.1.1创建Generic Dao,它包含一个与JPA findByExample
竞争的通用过滤器,请参阅以下文件:
在最后一个文件中,我尝试使用通用过滤器功能通过其注册的电子邮件查找用户,如下所示:
// this will implicitly exec and wait indefinitely for the
// db.run Future to complete
import dao.ExecHelper._
def findByEmail(email: String): Option[UserRow] = {
userDao.filter(_.email === email).headOption
}
但这会产生编译错误:
[error] /home/bravegag/code/play-authenticate-usage-scala/app/services/UserService.scala:35: value === is not a member of String
[error] userDao.filter(email === _.email).headOption
[error] ^
[error] /home/bravegag/code/play-authenticate-usage-scala/app/services/UserService.scala:35: ambiguous implicit values:
[error] both value BooleanOptionColumnCanBeQueryCondition in object CanBeQueryCondition of type => slick.lifted.CanBeQueryCondition[slick.lifted.Rep[Option[Boolean]]]
[error] and value BooleanCanBeQueryCondition in object CanBeQueryCondition of type => slick.lifted.CanBeQueryCondition[Boolean]
[error] match expected type slick.lifted.CanBeQueryCondition[Nothing]
[error] userDao.filter(email === _.email).headOption
[error] ^
有人可以建议如何改进下面filter
函数的隐式声明来解决这个编译错误吗?
过滤函数的实现(在GenericDaoImpl.scala中找到)是:
// T is defined above as T <: Table[E] with IdentifyableTable[PK]
override def filter[C <: Rep[_]](expr: T => C)
(implicit wt: CanBeQueryCondition[C]) : Future[Seq[E]] =
db.run(tableQuery.filter(expr).result)
答案 0 :(得分:3)
据我所知,您只是缺少UserService
中的个人资料API导入。
只需在此处添加导入:import profile.api._
即可。