why it returns 0 records with slick and playframework

31 Views Asked by At

There is a users table in the database. However, when i use the following scala code in playframework, it returns 0 records.

case class User(id: Option[Int], username: String, email: String,
password: String, role: String)

class Users(tag: Tag) extends Table[User](tag, "users") {
  def id = column[Int]("id", O.PrimaryKey, O.AutoInc, O.NotNull)
  def username = column[String]("username", O.NotNull)
  def email = column[String]("email", O.NotNull)
  def password = column[String]("password", O.NotNull)
  def role = column[String]("role", O.NotNull)
  def * = (id.?, username, email, password, role) <> (User.tupled, User.unapply _)
}

object Users {
  val users = TableQuery[Users]

  def findByUsernameAndPassword(username: String, encryptedPassword: String)(implicit session: Session): Option[User] = {
      users.where(_.username === "user1@localhost").firstOption
}

The generated SQL statement by the code is as below:

select x2."id", x2."username", x2."email", x2."password", x2."role" from "users" x2 where x2."username" = 'user1@localhost'

When i run the sql directly in the database, it returns the user record correctly.

0

There are 0 best solutions below