piotr-kalanski / class2sql   0.1.6

Apache License 2.0 GitHub

SQL insert statements generator based on Scala case class.

Scala versions: 2.11

class2sql

SQL insert and select statements generator based on Scala case class.

Build Status codecov.io Stories in Ready License

Table of contents

Goals

  • Provide simple tool for generating SQL inserts based on Scala case classes
  • Provide easy API to query JDBC table and map result to Scala case class

Getting started

Include dependencies

"com.github.piotr-kalanski" % "class2sql_2.11" % "0.1.0"

or

<dependency>
    <groupId>com.github.piotr-kalanski</groupId>
    <artifactId>class2sql_2.11</artifactId>
    <version>0.1.0</version>
</dependency>

Examples

Generate inserts

import com.datawizards.class2jdbc._

case class Person(name: String, age: Int)

val data = Seq(Person("p1", 1), Person("p2", 2))
generateInserts(data)
INSERT INTO Person(name,age) VALUES('p1',1)
INSERT INTO Person(name,age) VALUES('p2',2)

Select from table

import com.datawizards.jdbc2class._

case class Person(name: String, age: Int)

val connectionString = "jdbc:h2:mem:test"
val connection = DriverManager.getConnection(connectionString, "", "")
selectTable[Person](connection, "people")