slick auto-generated Models in sourceManaged folder: how to access them in a Controller?

349 views Asked by At

in play 2.5, I am using the slick codegenerator from com.typesafe.slick "com.typesafe.slick" %% "slick-codegen" % "3.1.1" % "compile" and it works fine: the auto-generated Slick data model is generated to the file target/scala-2.11/src_managed/slick/dao/Tables.scala.

My question: how can I access the generated Models and TableQuery objects from a Controller, let's say app/controllers/myDAOController.scala ? Any hints or a working example would be highly appreciated. Thank you!

1

There are 1 answers

6
Thomas Lehoux On

Just add

import Tables._

in your Controller. You will be able to use all your models.

Example: Here is your table:

create table IF NOT EXISTS "COMPANIES" ("ID" INTEGER NOT NULL,"NAME" VARCHAR NOT NULL);

You will access the generated Companies model like this:

val myCompanyName = Companies.filter(_.id === 10).map(_.name)

See a complete example here : https://github.com/slick/slick-codegen-example/blob/master/src/main/scala/Example.scala