R2r
R2r

Reputation: 1647

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

Upvotes: 1

Views: 970

Answers (1)

Akos Krivachy
Akos Krivachy

Reputation: 4966

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] = {

Upvotes: 1

Related Questions