I'm using Slick 2.0 and I have the following User
case class:
case class User(id: Option[Long], email: String, password: String)
class Users(tag: Tag) extends Table[User](tag, "user") {
def id = column[Long]("id", O.PrimaryKey, O.AutoInc)
def email = column[String]("email")
def password = column[String]("password")
def * = (id.?, email, password) <> ((User.apply _).tupled, User.unapply _)
}
and I have the following function getting a user via their database id:
def findOneById(id: Long) = DB.withSession { implicit session =>
val result = (for {
u <- users if u.id === id
} yield (u.id, u.email, u.password)).first
User(Option(result._1), result._2, result._3)
}
Is there an easier way to convert the Seq response back result
into the User
case class?