Best practice to integrate slick code generation into play2

268 views
Skip to first unread message

Lukas Weber

unread,
Feb 17, 2014, 1:29:52 PM2/17/14
to play-fr...@googlegroups.com
I'm pretty new to both play and slick. But given that slick is where relational DB integration in play is going, I'm trying to put together a project which combine the two in the right way. 

I've got the new slick code generation feature working which is a nice thing (from DB to slick code), but I wonder what the right way is to integrate it in a play2 project. The codegen generates a Tables.scala defining all the case classes, TableQueries etc. encapsulated in a Trait "Tables". I would want to have the main case classes along with helper methods etc. in separate Users.scala, Companies.scala etc. files in the models package and keep the Tables.scala separate so that it can be regnerated upon schema changes. 

So how can I keep things clean without copy-pasting code from the codegenerator output? 

It would be great to have a full example showcasing play2 + a couple of models + latest slick and code generation + schema evolutions + suggested workflow. 

Many thanks for feedback, it's much appreciated. Hopefully it's not obvious and I'm simply not seeing it .. 

Will Sargent

unread,
Feb 18, 2014, 7:25:57 PM2/18/14
to play-fr...@googlegroups.com
https://github.com/lunatech-labs/lunatech-securesocial-poc has Slick 2 integrated, but does not have the codegen feature working.  There are also a number of Typesafe activator templates which I think use Slick 1.x.

The slick code generation feature is something that's not integrated into Play yet -- there is a codegen example at https://github.com/slick/slick-codegen-example but you will need to integrate that into Play's Build.scala file manually.

Will.

Will Sargent
Consultant, Professional Services
Typesafe, the company behind Play Framework, Akka and Scala


--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to play-framewor...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Djon

unread,
Feb 19, 2014, 11:10:51 AM2/19/14
to play-fr...@googlegroups.com
Hi. What is about play-slick? There are some samples for slick 1.0 and 2.0.

Regards
Djon

Lukas Weber

unread,
Feb 19, 2014, 1:57:50 PM2/19/14
to play-fr...@googlegroups.com
Hi Will, 
thanks a bunch for replying - much appreciated. I have looked at the lunatech example as well as the codegen one (Build.scala etc. worked fine) and found them both very helpful. However I struggled with what I assumed to be a reasonably common use case (and I might be wrong): 
  • codegen gives me a single file (let's call it Tables.scala) with all of the case classes, TableQueries, "class Users(tag: Tag) extends Table[UsersRow](tag, "users")" etc. in it, but
  • as the the lunatech example shows, it would be nice to have some helper methods within those classes to simplify access to my models
The only way I could see to combine codegen with having clearly set up models (models/User.scala etc.) would be to copy/paste code from Tables.scala into User.scala and all other models. This would obviously be tedious and ruin the possibility to re-generate code after a schema change. 

If you can point me in a direction on how to do this right, it would be much appreciated. 
Or maybe copy-pasting or manual code is the way to go at this point. 

Cheers
Lukas

Will Sargent

unread,
Feb 19, 2014, 5:10:26 PM2/19/14
to play-fr...@googlegroups.com

Will Sargent
Consultant, Professional Services
Typesafe, the company behind Play Framework, Akka and Scala


Lukas Weber

unread,
Feb 20, 2014, 5:28:00 AM2/20/14
to play-fr...@googlegroups.com
Great .. taking a look. Thanks Will. 
Reply all
Reply to author
Forward
0 new messages