kentongray / sbt-slick

Slick Code Generation Plugin

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Slick Code Generation Plugin

This plugin allows you to easily generate slick Table schemas. Take a look at the test-project for example configurations.

Getting started

Add the plugin in your plugins.sbt

// something like that oO
resolvers += Resolver.url(
   "mukis-sbt-plugin-releases",
   url("http://dl.bintray.com/muuki88/sbt-plugins/"))(Resolver.ivyStylePatterns)

addSbtPlugin("de.mukis" % "sbt-slick" % "0.2")

Enable a database of your choice an configure it.

build.sbt

Make sure to add slick and the slickTask to the sourceGenerators

libraryDependencies ++= Seq(
   "com.typesafe.slick" %% "slick" % "2.1.0",
   "com.typesafe.slick" %% "slick-codegen" % "2.1.0"
)

sourceGenerators in Compile <+= slickGenTables

You can change the root package for your code with slickPackage.

slickPackage := "models" // default

H2

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")

MySql

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.

About

Slick Code Generation Plugin

License:Apache License 2.0


Languages

Language:Scala 100.0%