diff options
author | Stewart Stewart <stewinsalot@gmail.com> | 2017-02-24 04:12:50 -0500 |
---|---|---|
committer | Stewart Stewart <stewinsalot@gmail.com> | 2017-02-24 04:12:50 -0500 |
commit | 3a9d4366d7eda68145aaafc35619cf3e9c1a4d30 (patch) | |
tree | f0f6411c3572458a812c3cb2c3155eda40e98d3e /src/main | |
parent | 8fb0784cf220f72bc5aca87566e620b2d935b33c (diff) | |
download | slick-codegen-plugin-3a9d4366d7eda68145aaafc35619cf3e9c1a4d30.tar.gz slick-codegen-plugin-3a9d4366d7eda68145aaafc35619cf3e9c1a4d30.tar.bz2 slick-codegen-plugin-3a9d4366d7eda68145aaafc35619cf3e9c1a4d30.zip |
stub out row/table OutputHelpers
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/scala/NamespacedCodegen.scala | 2 | ||||
-rw-r--r-- | src/main/scala/OutputHelpers.scala | 57 |
2 files changed, 57 insertions, 2 deletions
diff --git a/src/main/scala/NamespacedCodegen.scala b/src/main/scala/NamespacedCodegen.scala index f08bd6c..08c0efd 100644 --- a/src/main/scala/NamespacedCodegen.scala +++ b/src/main/scala/NamespacedCodegen.scala @@ -97,7 +97,7 @@ abstract class Generator( schemaImports: List[String], typeReplacements: Map[String, String]) extends SourceCodeGenerator(schemaOnlyModel) - with OutputHelpers { + with OOutputHelpers { override val imports = schemaImports.map("import " + _).mkString("\n") diff --git a/src/main/scala/OutputHelpers.scala b/src/main/scala/OutputHelpers.scala index 3a184a4..2a3641e 100644 --- a/src/main/scala/OutputHelpers.scala +++ b/src/main/scala/OutputHelpers.scala @@ -1,4 +1,4 @@ -trait OutputHelpers extends slick.codegen.OutputHelpers { +trait OOutputHelpers extends slick.codegen.OutputHelpers { def imports: String @@ -25,3 +25,58 @@ trait OutputHelpers extends slick.codegen.OutputHelpers { |}""".stripMargin.trim() } } + +import slick.codegen.{SourceCodeGenerator, OutputHelpers} + +trait TableFileGenerator { self: SourceCodeGenerator => + def writeTablesToFile(folder:String, pkg: String, fileName: String): Unit +} + +trait RowFileGenerator { self: SourceCodeGenerator => + def writeRowsToFile(folder:String, pkg: String, fileName: String): Unit +} + +// Dirty work to hide OutputHelpers +trait TableOutputHelpers extends TableFileGenerator with OutputHelpers { self: SourceCodeGenerator => + + def packageTableCode: String = + """|${headerComment.trim().lines.map("// " + _).mkString("\n")} + |package $pkg + |package $schemaName + | + |$imports + | + |/** Stand-alone Slick data model for immediate use */ + |// TODO: change this to `object tables` + |package object $schemaName extends { + | val profile = $profile + |} with Tables + | + |/** Slick data model trait for extension, choice of backend or usage in the cake pattern. (Make sure to initialize this late.) */ + |trait Tables${parentType.fold("")(" extends " + _)} { + | import profile.api._ + | ${indent(code)} | + |""".stripMargin.trim() + + def writeTablesToFile(folder:String, pkg: String, fileName: String): Unit = { + writeStringToFile(content = packageTableCode, folder = folder, pkg = pkg, fileName = fileName) + } +} + +trait RowOutputHelpers extends RowFileGenerator with OutputHelpers { self: SourceCodeGenerator => + + def packageRowCode: String = + """|${headerComment.trim().lines.map("// " + _).mkString("\n")} + |/** Definitions for table rows types of database schema $schemaName */ + |package $pkg + |package $schemaName + | + |$imports + | + |$code + |""".stripMargin.trim() + + def writeRowsToFile(folder:String, pkg: String, fileName: String): Unit = { + writeStringToFile(content = packageRowCode, folder = folder, pkg = pkg, fileName = fileName) + } +} |