Reputation: 803
Using Play framework 2.4.3, and Slick 3.1
I have the following Model:
package models
import slick.driver.H2Driver.simple._
import slick.driver.H2Driver.api.Table
import slick.lifted.Tag
case class Subject(name: String, description: String)
/* Table mapping
*/
class SubjectsTable(tag: Tag) extends Table[Subject](tag, "SUBJECT") {
def name = column[String]("name", O.PrimaryKey)
def description = column[String]("description", O.NotNull)
def * = (name, description) <>(Subject.tupled, Subject.unapply _)
}
And I get a load of errors, that are rather unclear. The amount of errors clearly implies that I've used an outdated tutorial to copy the structure of my Model class from (my Manning Play for Scala book also does not cover this..) or just wrong imports.. I can't find any solid tutorial online for using Slick with Play Framework, is this really all Play has to offer?
[error] /app/models/Subject.scala:3: value simple is not a member of object slick.driver.H2Driver
[error] import slick.driver.H2Driver.simple._
[error] ^
[error] /app/controllers/Subjects.scala:25: type arguments [controllers.Subjects] conform to the bounds of none of the overloaded alternatives of
[error] value apply: [E <: slick.lifted.AbstractTable[_]]=> slick.lifted.TableQuery[E] <and> [E <: slick.lifted.AbstractTable[_]](cons: slick.lifted.Tag => E)slick.lifted.TableQuery[E]
[error] val subjects: TableQuery[Subjects] = TableQuery[Subjects]
[error] ^
[error] /app/controllers/Subjects.scala:34: value all is not a member of slick.lifted.TableQuery[controllers.Subjects]
[error] val allSubjects = dbConfig.db.run(subjects.all())
[error] ^
[error] /app/models/Subject.scala:13: could not find implicit value for parameter tt: slick.ast.TypedType[String]
[error] def name = column[String]("name", O.PrimaryKey)
[error] ^
[error] /app/models/Subject.scala:15: value NotNull is not a member of slick.driver.H2Driver.ColumnOptions
[error] def description = column[String]("description", O.NotNull)
[error] ^
[error] /app/models/Subject.scala:15: could not find implicit value for parameter tt: slick.ast.TypedType[String]
[error] def description = column[String]("description", O.NotNull)
[error] ^
[error] /app/tables/Subjects.scala:7: wrong number of type arguments for slick.driver.H2Driver.api.Table, should be 1
[error] class Subjects(tag: Tag) extends Table[String, String](tag, "SUBJECTS") {
I tried to use the file from a tutorial here
Something like a link to a tutorial or Github project is also fine if my question is too broad. I just can't start developing a sensible application like this. (Please don't refer to the Play Framework docs, they don't provide any proper info regarding this)
Upvotes: 1
Views: 682
Reputation:
In your build.sbt
add as dependency
"com.h2database" % "h2" % "1.4.190"
and just import
import slick.driver.H2Driver.api._
import slick.lifted.Tag
Upvotes: 0
Reputation: 1224
It looks like the example you are using is outdated. The activator-play-slick project that the example belongs to is for Play 2.3 and Slick 0.7.0.
The slick.driver.H2Driver.simple._
API was deprecated in earlier versions of Slick and has now been removed completely. Instead, you should be using:
import slick.driver.H2Driver.api._
import slick.lifted.Tag
Further, the option O.NotNull
has also been removed from Slick 3.1. and will cause a compilation error. Instead, you specify a not null by simply using the a non-Option type as you already have. E.g.:
def stringCol = column[String]("string_col")
For nullable fields you wrap the type in an option, so a nullable string would look something like:
def nullableStringCol = column[Option[String]]("nullable_string_col")
You can find some more updated examples of how to specify in the latest slick documentation here. This is quite a bit more comprehensive that what is included in the Play documentation.
Upvotes: 1