I have a class User
:
case class User (id: Int, name: String)
And I would like to map the rows from a query using Anorm Stream API. I have tried with this code:
val selectUsers = SQL("SELECT id, name FROM users")
val users = selectUsers().map(
user => User(0, user.name)
).toList
But I get an error:
Error raised is : value name is not a member of play.db.anorm.SqlRow
on
user => User(0, user.↓name)
How can I map the SqlRow
to a class?
As suggested by Ricardo, I tried:
object User extends Magic[User]
val users: List[User] = SQL("SELECT * FROM users").as(User*)
But with this code I get an RuntimeException occured : ColumnNotFound(User.id)
on:
val users: List[User] = SQL("SELECT * FROM users").as(User*)
Any suggestions? Am I supposted to have the User
object in the line right before? and I still have my case class User
.
Magic
with PostgreSQL. – Com