This plugin allows you to easily generate slick Table schemas.
Take a look at the test-project
for example configurations.
Add the plugin in your plugins.sbt
With sbt 0.13.6+
resolvers += Resolver.bintrayRepo("muuki88", "sbt-plugins")
For older versions use
resolvers += Resolver.url(
"mukis-sbt-plugin-releases",
url("http://dl.bintray.com/muuki88/sbt-plugins/"))(Resolver.ivyStylePatterns)
addSbtPlugin("de.mukis" % "sbt-slick" % "0.3")
addSbtPlugin("de.mukis" % "sbt-slick" % "0.4")
Enable a database of your choice an configure it.
Make sure to add slick and the slickTask to the sourceGenerators
val slickVersion = "x.y.z"
libraryDependencies ++= Seq(
"com.typesafe.slick" %% "slick" % slickVersion,
"com.typesafe.slick" %% "slick-codegen" % slickVersion
)
sourceGenerators in Compile <+= slickGenTables
You can change the root package for your code with slickPackage
.
slickPackage := "models" // default
For the very simple in memory solution with a provided import.sql
libraryDependencies += "com.h2database" % "h2" % "1.3.170"
enablePlugins(SlickCodeGenH2)
// slickUrl is a function from databaseName:Option[String] => url:String
slickUrl := { _ => s"jdbc:h2:mem:test;INIT=runscript from '${baseDirectory.value / "h2.create.sql"}'" }
Or you can just add the databases and take care of the creation yourself
enablePlugins(SlickCodeGenH2)
slickDatabases ++= Seq("user", "cities")
libraryDependencies += "mysql" % "mysql-connector-java" % "5.1.34"
enablePlugins(SlickCodeGenMySql)
slickUser := Some("test")
slickPassword := Some("test")
slickDatabases += "your-db"
This will generate the mysql tables.