piotr-kalanski / dbtable2class   0.3.2

Apache License 2.0 GitHub

Generate Scala case class based on database table metadata

Scala versions: 2.11

dbtable2class

Generate Scala case class based on database table metadata

Build Status codecov.io Stories in Ready License

Table of contents

Goals

  • Generate Scala case class based on database table metadata

Getting started

Include dependencies

"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>

Examples

Generate from H2

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
)

Generate output to directory

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")
  )
)