I have the following case class:
case class User (id: Option[Long] = None, name: String = "", lastName: String = "", login: String = "", password: String = "")
and the following table presentation:
class Users(tag: Tag) extends Table[User](tag,"t_users"){
def id = column[Option[Long]]("id", O.PrimaryKey, O.AutoInc)
def name = column[String]("name")
def lastName = column[String]("lastName")
def login = column[String]("login", O.NotNull)
def password = column[String]("password")
def * = (id, name, lastName, login, password) <> ((User.apply _).tupled, User.unapply _)
}
I'd like to perform a query, which would list some "users" but without the password.
I could do this:
def list(page: Int = 0, pageSize: Int = 10, filter: String = "%")(implicit s: Session): Page[User] = {
val offset = pageSize * (page -1)
val query = (for {
u <- users
if u.name.toLowerCase like filter.toLowerCase()
} yield u)
query.drop(offset).take(pageSize)
val totalRows = count(s)
val result = query.list
Page(result,page,offset,totalRows)
}
which would bring me the users full filled, but I'd like to perform a yield like this:
yield User(u.id,u.name,u.lastName,u.login) // bound to a User
Is it possible?
EDIT
I could make it accept the yield by:
yield User(u.id.asInstanceOf[Option[Long]],u.name.asInstanceOf[String],u.lastName.asInstanceOf[String],u.login.asInstanceOf[String],""))
but now it gives me an error at
u <- users
saying:
No matching Shape found. Slick does not know how to map the given types. Possible causes: T in Table[T] does not match your * projection. Or you use an unsupported type in a Query (e.g. scala List). Required level: scala#23.slick#2774.lifted#19028.FlatShapeLevel#24408 Source type: models#29.User#17383 Unpacked type: T#10265565 Packed type: G#10265564
not enough arguments for method map#59065: (implicit shape#10265576: scala#23.slick#2774.lifted#19028.Shape#24129[_ <: scala#23.slick#2774.lifted#19028.FlatShapeLevel#24408, models#29.User#17383, T#10265565, G#10265564])scala#23.slick#2774.lifted#19028.Query#23982[G#10265564,T#10265565,Seq#3031]. Unspecified value parameter shape.
result
will be a list of triples. – Ende Neu