Create MySQL connection in Playframework using slick

I am trying to connect to mysql database using slick 1.0.0.

What i have done so far:

in Build.scala I added

val appDependencies = Seq( anorm, "mysql" % "mysql-connector-java" % "5.1.24", "com.typesafe.slick" % "slick_2.10" % "1.0.0", "org.slf4j" % "slf4j-nop" % "1.6.4" ) 

in application.conf

 db.default.driver=com.mysql.jdbc.Driver db.default.url="url to mysql db" db.default.user=user db.default.pass=password 

and now I'm trying to read a record from the database. For this I have a model

 package models import scala.slick.driver.MySQLDriver.simple._ import Database.threadLocalSession object Organisations extends Table[(Int, String)]("Organisation") { def id = column[Int]("id", O.PrimaryKey) def name = column[String]("name") def * = id ~ name } 

and now I would just like to output the entries

 val orgs = for { o <- Organisations } yield o.name println("Length" + orgs.toString()) 

But that will not work. I'm sure I got a lot of errors, but it seems there were no true slutorial tutorials with mysql.

Thank you for your patience, and I hope my explanations are clear.

+6
source share
3 answers

Using Slick requires a little template, creating a session and all that, checking out the Play-Slick plugin written by Fredrik Ekholdt (typesafe)!

It does everything for you, and there are good examples on the wiki on how to use it.

https://github.com/freekh/play-slick/

+5
source

The new Slick 2.0 also comes with a code generator that can be used with the evolutions of the Play Framework.

This means that you no longer need to write a template for Slick . Just write your changes to the database using evolution files and immediately access the new tables from your code.

Here you can find the full example using MySQL:

https://github.com/papauschek/play-slick-evolutions

And more info on how this works:

http://blog.papauschek.com/2013/12/slick-2-0-code-generator-play-framework-evolutions/

+2
source

The Play team is also working on a spotted benchmark for Techempower. This is a work in progress, but soon we will raise PR to the completed version (the next 24 hours, which I suspect):

https://github.com/nraychaudhuri/FrameworkBenchmarks/tree/adding_missing_slickness/play-slick

+1
source

Source: https://habr.com/ru/post/945081/


All Articles