diff options
author | Stewart Stewart <stewinsalot@gmail.com> | 2016-09-09 15:01:29 -0400 |
---|---|---|
committer | Stewart Stewart <stewinsalot@gmail.com> | 2016-09-09 15:01:29 -0400 |
commit | f932919f6bc57f5d080dd42e17af83af0a6ea080 (patch) | |
tree | b08432c773a1ce9daa197a23c440f1a92cad5d16 /src/main/scala | |
parent | b70191412c26212fddca06b23d70a6d467e1ff7c (diff) | |
download | slick-codegen-plugin-f932919f6bc57f5d080dd42e17af83af0a6ea080.tar.gz slick-codegen-plugin-f932919f6bc57f5d080dd42e17af83af0a6ea080.tar.bz2 slick-codegen-plugin-f932919f6bc57f5d080dd42e17af83af0a6ea080.zip |
take schemas as a parameter
Diffstat (limited to 'src/main/scala')
-rw-r--r-- | src/main/scala/CodegenPlugin.scala | 5 | ||||
-rw-r--r-- | src/main/scala/NamespacedCodegen.scala | 12 |
2 files changed, 6 insertions, 11 deletions
diff --git a/src/main/scala/CodegenPlugin.scala b/src/main/scala/CodegenPlugin.scala index 895e674..d6ac8c8 100644 --- a/src/main/scala/CodegenPlugin.scala +++ b/src/main/scala/CodegenPlugin.scala @@ -10,13 +10,12 @@ object CodegenPlugin extends AutoPlugin { 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 schemas = "patients,portal,work_queues,confidential,case_accessioning,samples.samples,samples.subsamples,samples.shipment_preps,samples.collection_methods,experiments.experiments,experiments.exp_types,experiments.somatic_snvs_indels_filtered,samples.basic_diagnosis,samples.molecular_tests,samples.sample_pathology,samples.path_molecular_tests" - val uri = new java.net.URI(dbConfigURI.value) - codegen.NamespacedCodegen.run(uri, pkg.value, tablesFilename.value, rowsFilename.value, schemas) + codegen.NamespacedCodegen.run(uri, pkg.value, tablesFilename.value, rowsFilename.value, schemas.value) Seq(file(tablesFilename.value), file(rowsFilename.value)) } diff --git a/src/main/scala/NamespacedCodegen.scala b/src/main/scala/NamespacedCodegen.scala index ca9897e..b853e9a 100644 --- a/src/main/scala/NamespacedCodegen.scala +++ b/src/main/scala/NamespacedCodegen.scala @@ -22,11 +22,8 @@ import java.io.FileWriter // generator places the relevant generated classes into separate // objects--a "a" object, and a "b" object) object NamespacedCodegen { - def parseSchemaList(schemaList: String): Map[String, List[String]] = { - val sl = schemaList.split(",").filter(_.trim.nonEmpty) - val tables: List[String] = sl.filter(_.contains(".")).toList - val schemas: List[String] = sl.filter(s => !(s.contains("."))).toList - + def parseSchemaList(schemaTableNames: List[String]): Map[String, List[String]] = { + val (tables, schemas) = schemaTableNames.partition(_.contains(".")) val mappedSchemas = schemas.map(_ -> List()).toMap val mappedTables = tables.groupBy(_.split("\\.")(0)).map { case (key, value) => (key, value.map(_.split("\\.")(1)).asInstanceOf[List[String]]) @@ -83,12 +80,11 @@ object NamespacedCodegen { pkg: String, filename: String, typesFilename: String, - schemaList: String + schemaTableNames: List[String] ): Unit = { val dc = DatabaseConfig.forURI[JdbcProfile](uri) val slickDriver = if(dc.driverIsObject) dc.driverName else "new " + dc.driverName - - val mappedSchemas = parseSchemaList(schemaList) + val mappedSchemas = parseSchemaList(schemaTableNames) val dbModel = Await.result(dc.db.run(createFilteredModel(dc.driver, mappedSchemas)), Duration.Inf) //finally dc.db.close |