Skip to content

Instantly share code, notes, and snippets.

@harmeetsingh0013
Created June 27, 2017 09:56
Show Gist options
  • Save harmeetsingh0013/244e67eef3368e0f14a9ea3dded805ce to your computer and use it in GitHub Desktop.
Save harmeetsingh0013/244e67eef3368e0f14a9ea3dded805ce to your computer and use it in GitHub Desktop.
lazy val slickVersion = "3.2.0"
libraryDependencies ++= Seq(
"com.typesafe.slick" %% "slick" % slickVersion,
"com.typesafe.slick" %% "slick-hikaricp" % slickVersion,
"com.typesafe.slick" %% "slick-codegen" % slickVersion % "compile",
"org.postgresql" % "postgresql" % "9.4.1212",
"com.typesafe.slick" %% "slick-testkit" % "3.2.0" % "test"
)
// code generation task
lazy val slick = TaskKey[Seq[File]]("gen-tables")
lazy val slickCodeGenTask = (sourceManaged, dependencyClasspath in Compile, runner in Compile, streams) map { (dir, cp, r, s) =>
val outputDir = (dir / "slick").getPath // place generated files in sbt's managed sources folder
val url = "jdbc:postgresql://localhost:5432/github_info?user=postgres&password=root&sslmode=disable" // 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.jdbc.PostgresProfile"
val pkg = "com.knoldus.github.models"
toError(r.run("slick.codegen.SourceCodeGenerator", cp.files, Array(slickDriver, jdbcDriver, url, outputDir, pkg), s.log))
val fname = outputDir + "/com/knoldus/github/models/Tables.scala"
Seq(file(fname))
}
slick <<= slickCodeGenTask // register manual sbt command
sourceGenerators in Compile <+= slickCodeGenTask // register automatic code generation on every compile, remove for only manual use
testOptions += Tests.Argument(TestFrameworks.JUnit, "-q", "-v", "-s", "-a")
parallelExecution in Test := false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment