Created
June 29, 2016 13:02
-
-
Save vovateleport/1da5bfb6d5122e7721feebadb7de6b5a to your computer and use it in GitHub Desktop.
slick gen tables
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sbt.Project.projectToRef | |
lazy val slickV = "3.1.1" | |
lazy val scalaV = "2.11.8" | |
lazy val commonSettings = Seq( | |
scalaVersion := scalaV, | |
name := "playslick", | |
version := "1.0" | |
) | |
lazy val jsProjects = Seq(client) | |
lazy val play = (project in file("play")) | |
.settings(commonSettings: _*) | |
.enablePlugins(PlayScala) | |
.settings( | |
routesGenerator := InjectedRoutesGenerator,// Play provides two styles of routers, one expects its actions to be injected, the other, legacy style, accesses its actions statically. | |
scalaJSProjects := jsProjects, | |
pipelineStages := Seq(scalaJSProd), | |
libraryDependencies ++= Seq( | |
"com.vmunier" %% "play-scalajs-scripts" % "0.3.0", | |
"com.lihaoyi" %% "autowire" % "0.2.5", | |
"com.lihaoyi" %% "upickle" % "0.3.9", | |
"org.postgresql" % "postgresql" % "9.4.1208.jre7", | |
"com.typesafe.slick" %% "slick" % slickV, | |
"com.typesafe.slick" %% "slick-codegen" % slickV, | |
"org.apache.solr" % "solr-solrj" % "6.0.0" | |
) | |
) | |
.aggregate(jsProjects.map(projectToRef): _*) | |
.dependsOn(sharedJvm, dabaser) | |
lazy val client = (project in file("client")) | |
.enablePlugins(ScalaJSPlugin, ScalaJSPlay) | |
.settings(commonSettings:_*) | |
.settings( | |
persistLauncher := true, | |
persistLauncher in Test := false, | |
libraryDependencies ++= Seq( | |
"com.lihaoyi" %%% "autowire" % "0.2.5", | |
"com.lihaoyi" %%% "upickle" % "0.3.9", | |
"com.github.japgolly.scalajs-react" %%% "core" % "0.11.0", | |
"com.github.japgolly.scalajs-react" %%% "ext-scalaz72" % "0.11.0" | |
), | |
jsDependencies ++= Seq( | |
"org.webjars.bower" % "react" % "15.0.1" | |
/ "react-with-addons.js" | |
minified "react-with-addons.min.js" | |
commonJSName "React", | |
"org.webjars.bower" % "react" % "15.0.1" | |
/ "react-dom.js" | |
minified "react-dom.min.js" | |
dependsOn "react-with-addons.js" | |
commonJSName "ReactDOM", | |
"org.webjars.bower" % "react" % "15.0.1" | |
/ "react-dom-server.js" | |
minified "react-dom-server.min.js" | |
dependsOn "react-dom.js" | |
commonJSName "ReactDOMServer" | |
) | |
) | |
.dependsOn(sharedJs) | |
lazy val shared = (crossProject.crossType(CrossType.Pure) in file("shared")) | |
.settings(scalaVersion := scalaV) | |
.jsConfigure(_ enablePlugins ScalaJSPlay) | |
lazy val sharedJvm = shared.jvm | |
lazy val sharedJs = shared.js | |
lazy val root = (project in file(".")) | |
.settings(commonSettings: _*) | |
.aggregate(play) | |
lazy val dabaser = (project in file("dabaser")) | |
.settings(commonSettings: _*) | |
.settings(name:="dabaser") | |
.settings( | |
libraryDependencies ++= Seq( | |
"org.postgresql" % "postgresql" % "9.4.1208.jre7", | |
"com.typesafe.slick" %% "slick" % slickV, | |
"com.typesafe.slick" %% "slick-codegen" % slickV, | |
"com.typesafe.slick" %% "slick-hikaricp" % slickV | |
), | |
slick <<= slickCodeGenTask // register manual sbt command | |
//sourceGenerators in Compile <+= slickCodeGenTask // register automatic code generation on every compile, remove for only manual use | |
) | |
lazy val slick = TaskKey[Seq[File]]("gen-tables") | |
lazy val slickCodeGenTask = (sourceDirectory, dependencyClasspath in Compile, runner in Compile, streams) map { (dir, cp, r, s) => | |
val outputDir = (dir / "main" / "scala").getPath // place generated files in sbt's managed sources folder | |
println("outputDir", outputDir) | |
val url = "jdbc:postgresql://192.168.99.100:5432/rnd?user=vova&password=vova" // connection info for a pre-populated throw-away, in-memory db for this demo, which is freshly initialized on every run | |
val jdbcDriver = "org.postgresql.Driver" | |
val slickDriver = "slick.driver.PostgresDriver" | |
val pkg = "rnd.slick" | |
toError(r.run("slick.codegen.SourceCodeGenerator", cp.files, Array(slickDriver, jdbcDriver, url, outputDir, pkg), s.log)) | |
val fname = outputDir + "/demo/Tables.scala" | |
Seq(file(fname)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment