我是Scala的新手。我尝试执行以下操作时遇到类型错误。为什么我的findByUUID方法错了?
case class User (token: String, email: String) {
}
class Users(tag: Tag) extends Table[User](tag, "USERS") {
def email = column[String]("EMAIL", O.PrimaryKey, O.AutoInc)
def token = column[String]("TOKEN")
def * = (token, email) <> (User.tupled, User.unapply)
}
object UsersManager {
def users = TableQuery[Users]
def findByUUID(token: String) = Option[User] {
DatabaseConfig.db.withSession { implicit session =>
users.filter(_.token === token).firstOption
}
}
}
以下是我从控制台获得的内容:
[error] found : Option[models.Users#TableElementType]
[error] required: models.User
[error] users.filter(_.token === token).firstOption
答案 0 :(得分:1)
你有一个小错字:
def findByUUID(token: String) = Option[User] {
应该是(查看=
标志所在的位置):
def findByUUID(token: String): Option[User] = {