aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/scala/NamespacedCodegen.scala34
1 files changed, 12 insertions, 22 deletions
diff --git a/src/main/scala/NamespacedCodegen.scala b/src/main/scala/NamespacedCodegen.scala
index 245a4ef..44826fe 100644
--- a/src/main/scala/NamespacedCodegen.scala
+++ b/src/main/scala/NamespacedCodegen.scala
@@ -91,10 +91,12 @@ object NamespacedCodegen {
var imports =
"import slick.model.ForeignKeyAction\n" +
- "import rows._\n" +
+ "import dbmodels.rows\n" +
( if(tables.exists(_.hlistEnabled)){
- "import slick.collection.heterogeneous._\n"+
- "import slick.collection.heterogeneous.syntax._\n"
+ "import slick.collection.heterogeneous._\n" +
+ "import slick.collection.heterogeneous.syntax._\n" +
+ "import com.drivergrp.core._\n" +
+ "import com.drivergrp.core.database._\n"
} else ""
) +
( if(tables.exists(_.PlainSqlMapper.enabled)){
@@ -113,23 +115,12 @@ object NamespacedCodegen {
.sortBy(_.model.name.table)
.map(_.code.mkString("\n"))
.mkString("\n\n")
- indent(s"object $schemaName {\n$tableCode")+"\n}\n"
+ indent(s"object $schemaName extends CoreDBMappers {\n$tableCode")+"\n}\n"
}.mkString("\n\n")
- val idType =
- if (typeFile)// Should not be defined here.
- """|case class Id[T](v: Int)
- |""".stripMargin
- else
- // This should be in a separate Implicits trait
- """|implicit def idTypeMapper[A] : BaseColumnType[Id[A]] =
- | MappedColumnType.base[Id[A], Int](_.v, Id(_))
- |import play.api.mvc.PathBindable
- |implicit def idPathBindable[A] : PathBindable[Id[A]] = implicitly[PathBindable[Int]].transform[Id[A]](Id(_),_.v)
- |""".stripMargin
- //pathbindable is play specific
- // Id works only with labdash Id
- imports + idType + schemata
+ val mapperTrait: String = """trait CoreDBMappers extends com.drivergrp.core.database.IdColumnTypes { override val database = com.drivergrp.core.database.Database.fromConfig("slick.db.default") }"""
+
+ imports + mapperTrait + "\n\n" + schemata
}
// This is overridden to output classfiles elsewhere
@@ -227,9 +218,8 @@ object NamespacedCodegen {
else model.tpe match {
// how does this type work out?
// There should be a way to add adhoc custom time mappings
- case "java.sql.Date" => "tools.Date"
- case "java.sql.Time" => "tools.Time"
- case "java.sql.Timestamp" => "tools.Time"
+ case "java.sql.Time" => "com.drivergrp.core.time.Time"
+ case "java.sql.Timestamp" => "com.drivergrp.core.time.Time"
case _ => super.rawType
}
}
@@ -243,7 +233,7 @@ object NamespacedCodegen {
fw.write(c)
fw.close()
}
- val disableScalariform = "filename/ format: OFF\n"
+ val disableScalariform = "// filename/ format: OFF\n"
val tablesSource = codegen(false).packageCode(slickDriver, pkg, "Tables", None)
val rowsSource = s"package $pkg.rows\n\n" + codegen(true).code