Trying to do first steps with SLICK but things do not seem to work or documentation is outdated

168 Views Asked by At

A custom source code generator was used in order to create the classes necessary for the MySQL database as described in this question: How to setup username and password with Slick's source code generator?

Then tried to follow the getting started guide in order to execute the most simple queries using SLICK and try out its capabilities.

The TableQuery vals created from source code generator do not have the attribute ddl in order to execute something like that: suppliers.ddl

Also I tried to create my own having a code like that: val models = TableQuery[Model]

So I tried this: models += ModelRow(...) but this is not working because compiler complains that model is not a string and also that a re-assignment to a val is being performed.

In addition the models.foreach(....) method does not exist.

I have started on the wrong foot here. Some help is required to get on the right track. Thank you

2

There are 2 best solutions below

0
On BEST ANSWER

Finally I figured out what needed to be done by combining several posts found in the internet

For busy developers there is a guide explaining the entire solution and how to integrate slick into play framework in a fast in this blog post: http://pligor.tumblr.com/post/75933978759/integrate-slick-2-0-into-play-the-easy-and-fast-way

Enjoy!

PS: Thanks @Martin Kolinek for the help

2
On

Seems like you are learning Scala and Slick at the same time. Make sure you take some time to learn Scala on its own. You need to be familiar with Scala concepts like val, etc. to make sense of Scala code. To sensibly understand compiler error messages you need to know a little more. E.g. that (like extension methods in C#) not every method in Scala actually exists inside the object it is called on. Some methods are put on from the outside using implicit conversions. But that only happens when you have the appropriate implicit conversions in scope. Otherwise the methods can simply not be found.

Try to start with this example project:

https://github.com/slick/slick-codegen-customization-example/tree/master

which is references here: http://slick.typesafe.com/doc/2.0.0/code-generation.html