diff options
author | Stewart Stewart <stewinsalot@gmail.com> | 2016-12-09 12:30:51 -0800 |
---|---|---|
committer | Stewart Stewart <stewinsalot@gmail.com> | 2016-12-09 12:30:51 -0800 |
commit | 74a591c058db982d41a547d3988cd9a8944ce44d (patch) | |
tree | ee31f0c8ab62f461e56becc7769c689ac3788265 /src/main/scala | |
parent | 30671a70025c62a45979b202d62557c1576c7f13 (diff) | |
download | slick-codegen-plugin-74a591c058db982d41a547d3988cd9a8944ce44d.tar.gz slick-codegen-plugin-74a591c058db982d41a547d3988cd9a8944ce44d.tar.bz2 slick-codegen-plugin-74a591c058db982d41a547d3988cd9a8944ce44d.zip |
add ddl code
Diffstat (limited to 'src/main/scala')
-rw-r--r-- | src/main/scala/NamespacedCodegen.scala | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/src/main/scala/NamespacedCodegen.scala b/src/main/scala/NamespacedCodegen.scala index a4bc8d8..7ee05df 100644 --- a/src/main/scala/NamespacedCodegen.scala +++ b/src/main/scala/NamespacedCodegen.scala @@ -126,6 +126,25 @@ class Generator(uri: URI, .sortBy(_.model.name.table) .map(_.code.mkString("\n")) .mkString("\n\n") + + val ddlCode = + (if (ddlEnabled) { + "\n/** DDL for all tables. Call .create to execute. */" + + ( + if (tableDefs.length > 5) + "\nlazy val schema: profile.SchemaDescription = Array(" + tableDefs + .map(_.TableValue.name + ".schema") + .mkString(", ") + ").reduceLeft(_ ++ _)" + else if (tableDefs.nonEmpty) + "\nlazy val schema: profile.SchemaDescription = " + tableDefs + .map(_.TableValue.name + ".schema") + .mkString(" ++ ") + else + "\nlazy val schema: profile.SchemaDescription = profile.DDL(Nil, Nil)" + ) + + "\n\n" + } else "") + val generatedSchema = s""" |object ${schemaName} extends { | val profile = slick.backend.DatabaseConfig.forConfig[slick.driver.JdbcProfile]("${uri @@ -133,7 +152,7 @@ class Generator(uri: URI, |} with $schemaBaseClass { | import profile.api._ | ${tableCode} - | + | ${ddlCode} |} |// scalastyle:on""".stripMargin |