Generate Scala case class based on database table metadata
- Generate Scala case class based on database table metadata
"com.github.piotr-kalanski" % "dbtable2class_2.11" % "0.3.1"
or
<dependency>
<groupId>com.github.piotr-kalanski</groupId>
<artifactId>dbtable2class_2.11</artifactId>
<version>0.3.1</version>
</dependency>
Example table in H2:
PEOPLE(
NAME VARCHAR,
AGE INT
)
val url = "jdbc:h2:mem:test"
ClassGenerator.generateClass(url, null, H2Dialect, TableClassMapping(database="TEST", schema="PUBLIC", table="PEOPLE", packageName="com.datawizards.model", className="Person"))
Result:
package com.datawizards.model
case class Person(
NAME: String,
AGE: Int
)
ClassGenerator.generateClassesToDirectory(
"target", url, null, H2Dialect, Seq(
TableClassMapping(database="TEST", schema="PUBLIC", table="T11", packageName="com.datawizards.model", className="Person"),
TableClassMapping(database="TEST", schema="PUBLIC", table="T22", packageName="com.datawizards.model", className="Book")
)
)