diff options
Diffstat (limited to 'src/main/scala/OutputHelpers.scala')
-rw-r--r-- | src/main/scala/OutputHelpers.scala | 72 |
1 files changed, 60 insertions, 12 deletions
diff --git a/src/main/scala/OutputHelpers.scala b/src/main/scala/OutputHelpers.scala index ce22f2a..97fb4e9 100644 --- a/src/main/scala/OutputHelpers.scala +++ b/src/main/scala/OutputHelpers.scala @@ -1,28 +1,76 @@ -trait OutputHelpers extends slick.codegen.OutputHelpers { +import slick.codegen.{SourceCodeGenerator, OutputHelpers} - def imports: String +trait TableOutputHelpers extends TableFileGenerator with OutputHelpers { + self: SourceCodeGenerator => - def headerComment: String = "" + def headerComment: String + def schemaName: String + def imports: String - override def packageCode(profile: String, - pkg: String, - container: String, - parentType: Option[String]): String = { - val traitName = container.capitalize + "SchemaDef" + def packageTableCode(headerComment: String, + pkg: String, + schemaName: String, + imports: String, + profile: String): String = s"""|${headerComment.trim().lines.map("// " + _).mkString("\n")} |package $pkg + |package $schemaName | |$imports | |/** Stand-alone Slick data model for immediate use */ - |object $container extends { + |// TODO: change this to `object tables` + |object `package` extends { | val profile = $profile - |} with $traitName + |} with Tables | |/** Slick data model trait for extension, choice of backend or usage in the cake pattern. (Make sure to initialize this late.) */ - |trait $traitName${parentType.fold("")(" extends " + _)} { + |trait Tables${parentType.fold("")(" extends " + _)} { | import profile.api._ | ${indent(code)} - |}""".stripMargin.trim() + |} + |""".stripMargin.trim() + + def writeTablesToFile(profile: String, + folder: String, + pkg: String, + fileName: String): Unit = { + writeStringToFile( + content = + packageTableCode(headerComment, pkg, schemaName, imports, profile), + folder = folder, + pkg = s"$pkg.$schemaName", + fileName = fileName) + } +} + +trait RowOutputHelpers extends RowFileGenerator with OutputHelpers { + self: SourceCodeGenerator => + + def headerComment: String + def schemaName: String + def imports: String + + def packageRowCode(headerComment: String, + schemaName: String, + pkg: String, + imports: String): String = + s"""|${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(headerComment, schemaName, pkg, imports), + folder = folder, + pkg = s"$pkg.$schemaName", + fileName = fileName) } } |