Search code examples
scalaplayframework-2.0slickfrm

Type mismatch in slick query


I'm new to Scala. I'm getting type errors when I try do following. WHy my findByUUID method is wrong?

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
    }
  }
}

Here is what I get from console:

[error]  found   : Option[models.Users#TableElementType]
[error]  required: models.User
[error]  users.filter(_.token === token).firstOption

Solution

  • You have a small typo:

    def findByUUID(token: String) = Option[User] {
    

    Should be (look at where the = sign is):

    def findByUUID(token: String): Option[User] = {