Skip to content
This repository was archived by the owner on Oct 14, 2018. It is now read-only.

Commit e02cb33

Browse files
committed
Update readme
1 parent a5def09 commit e02cb33

File tree

2 files changed

+67
-2
lines changed

2 files changed

+67
-2
lines changed

Readme.md

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,67 @@
11
# scala-db-codegen
22

3-
Generate Scala code from your database.
3+
Generate Scala code from your database to use with the incredble library [quill](https://github.com/getquill/quill).
44
Only tested with postgresql, but could in theory work with any jdbc compliant database.
55

6+
## What does it do?
7+
8+
Say you have some database with this schema
9+
10+
```sql
11+
create table test_users_main(
12+
id integer not null,
13+
name varchar(255),
14+
primary key (id)
15+
);
16+
17+
create table articles(
18+
id integer not null,
19+
author_id integer not null,
20+
is_published boolean
21+
);
22+
23+
ALTER TABLE articles
24+
ADD CONSTRAINT author_id_fk
25+
FOREIGN KEY (author_id)
26+
REFERENCES test_users_main (id);
27+
```
28+
29+
scala-db-codegen will then generate "type all the things!" code like this
30+
31+
```
32+
package tables
33+
import java.util.Date
34+
import io.getquill.WrappedValue
35+
36+
object Tables {
37+
/////////////////////////////////////////////////////
38+
// Articles
39+
/////////////////////////////////////////////////////
40+
case class Articles(id: Articles.Id, authorId: TestUsersMain.Id, isPublished: Articles.IsPublished)
41+
object Articles {
42+
def create(id: Int, authorId: Int, isPublished: Boolean): Articles = {
43+
Articles(Id(id), TestUsersMain.Id(authorId), IsPublished(isPublished))
44+
}
45+
case class Id(value: Int) extends AnyVal with WrappedValue[Int]
46+
case class IsPublished(value: Boolean) extends AnyVal with WrappedValue[Boolean]
47+
}
48+
49+
/////////////////////////////////////////////////////
50+
// TestUsersMain
51+
/////////////////////////////////////////////////////
52+
case class TestUsersMain(id: TestUsersMain.Id, name: TestUsersMain.Name)
53+
object TestUsersMain {
54+
def create(id: Int, name: String): TestUsersMain = {
55+
TestUsersMain(Id(id), Name(name))
56+
}
57+
case class Id(value: Int) extends AnyVal with WrappedValue[Int]
58+
case class Name(value: String) extends AnyVal with WrappedValue[String]
59+
}
60+
}
61+
```
62+
63+
It could in theory also generate the code differently.
64+
665
## CLI
766

867
```shell
@@ -37,6 +96,11 @@ Usage: db-codegen [options]
3796
3897
## Standalone library
3998
40-
TODO, look at source for now.
99+
```scala
100+
// 2.11 only
101+
libraryDependencies += "com.geirsson" %% "codegen" % "0.1.0"
102+
```
103+
104+
Consult the source usage, at least for now ;)
41105
42106

build.sbt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ lazy val `launaskil-codegen` =
3939
name := "codegen",
4040
organization := "com.geirsson",
4141
scalaVersion := "2.11.8",
42+
version := "0.1.0",
4243
packMain := Map("db-codegen" -> "com.geirsson.codegen.Codegen"),
4344
libraryDependencies ++= Seq(
4445
"com.geirsson" %% "scalafmt-core" % "0.3.0",

0 commit comments

Comments
 (0)