我是 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