Search code examples
scalaslickslick-3.0

Cannot make slick 3.2 Mapped table example working


I'm just trying to make "User" example working (http://slick.lightbend.com/doc/3.2.0/schemas.html#mapped-tables), but it doesn't compile.

As I'm targeting MySQL, I added th folowing imports :

import slick.jdbc.MySQLProfile.Table
import slick.jdbc._
import slick.lifted._

That didn't compiled either, I got a lot of errors like

Error:(16, 23) could not find implicit value for parameter tt: slick.ast.TypedType[Int]
  def id = column[Int]("id", O.PrimaryKey, O.AutoInc)

After looking for implicits, I added with MySQLProfile.ImplicitColumnTypes to the Users class extending Table:

class Users(tag: Tag) extends Table[User](tag, "users") with MySQLProfile.ImplicitColumnTypes

Now I'm stuck with

Error:(19, 15) value ? is not a member of slick.lifted.Rep[Int]
  def * = (id.?, first, last) <> (User.tupled, User.unapply _)

<> is not found either.

You may notice User.unapply _ instead of User.unapply as stated in doc; but the compiler was complaining whith User.unapply

What I'm I doing wrong ? Why is the doc so unclear ?


Solution

  • The code imports slick.jdbc.MySQLProfile.Table but instead it needs to bring in the whole api:

    import slick.jdbc.MySQLProfile.api._
    

    That will give you the implicts you were looking for, and the code should compile.


    BTW: the Slick examples are compiled

    Incidently, the Slick manual examples are compiled. This means you can get to the code to see if there are extra details in there you need.

    For example, for the page you linked to, if you scroll to the top there's an "Edit this page on github" link. Clicking that takes you to the source and in there you'll find a reference to the Scala source:

    .. includecode:: code/LiftedEmbedding.scala#mappedtable
    

    ...and that file is also in GitHub: LiftedEmbedding.scala

    A bit long-winded, but useful sometimes to know the examples are compiled and you can find them.

    The details of how that happens are just about to change to a different system, but the principles should remain the same. The details (filenames, import syntax) above will be different.