aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/CodegenPlugin.scala
blob: d6ac8c8a8fda44770f84ff4b44f646886e99d6e7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import sbt._
import sbt.Keys._
import complete.DefaultParsers._

object CodegenPlugin extends AutoPlugin {
  override def requires = sbt.plugins.JvmPlugin
  object autoImport {
    lazy val genTables = TaskKey[Seq[File]]("gen-tables")
    lazy val dbConfigURI = SettingKey[String]("uri for the database configuration")
    lazy val pkg = SettingKey[String]("package in which to place generated code")
    lazy val tablesFilename = SettingKey[String]("path for slick table models")
    lazy val rowsFilename = SettingKey[String]("path for row case classes")
    lazy val schemas = SettingKey[List[String]]("schemas and tables to process")

    lazy val slickCodeGenTask = Def.task {
      val uri = new java.net.URI(dbConfigURI.value)

      codegen.NamespacedCodegen.run(uri, pkg.value, tablesFilename.value, rowsFilename.value, schemas.value)

      Seq(file(tablesFilename.value), file(rowsFilename.value))
    }
  }
}