Reputation: 100
I am trying to start using slick. I have a h2-database and generated classes with scala.slick.model.codegen.SourceCodeGenerator. But when try I try following the examples and query my db using these classes I get scala-errors.
The generated code looks as follows:
/** Entity class storing rows of table User
* @param id Database column ID PrimaryKey
* @param firstname Database column FIRSTNAME
* @param lastname Database column LASTNAME */
case class UserRow(id: String, firstname: Option[String], lastname: Option[String])
/** GetResult implicit for fetching UserRow objects using plain SQL queries */
implicit def GetResultUserRow(implicit e0: GR[String], e1: GR[Option[String]]): GR[UserRow] = GR{
prs => import prs._
UserRow.tupled((<<[String], <<?[String], <<?[String]))
}
/** Table description of table USER. Objects of this class serve as prototypes for rows in queries. */
class User(tag: Tag) extends Table[UserRow](tag, "USER") {
def * = (id, firstname, lastname) <> (UserRow.tupled, UserRow.unapply)
/** Maps whole row to an option. Useful for outer joins. */
def ? = (id.?, firstname, lastname).shaped.<>({r=>import r._; _1.map(_=> UserRow.tupled((_1.get, _2, _3)))}, (_:Any) => throw new Exception("Inserting into ? projection not supported."))
/** Database column ID PrimaryKey */
val id: Column[String] = column[String]("ID", O.PrimaryKey)
/** Database column FIRSTNAME */
val firstname: Column[Option[String]] = column[Option[String]]("FIRSTNAME")
/** Database column LASTNAME */
val lastname: Column[Option[String]] = column[Option[String]]("LASTNAME")
}
/** Collection-like TableQuery object for table User */
lazy val User = new TableQuery(tag => new User(tag))
And this is my query:
val userResultList = for {
u <- User if u.id === "foo"
} yield u
which results in:
Error:(137, 29) value === is not a member of db.Tables.profile.simple.Column[String]
u <- User if u.id === user.id
^
What's wrong?
Upvotes: 0
Views: 1461
Reputation: 5763
For slick 2.x
, just import XXXDriver.simple._
and the compiler will be happy.
For slick 3.x
, its XXXDriver.api._
Upvotes: 7