1
1
# Quill Code Generator
2
2
3
- This library is designed to give you a few options as to what kind of
4
- schema to generate from JDBC metadata for quill. You can choose to generate
5
- either simple case classes or a combination of case classes and query schemas,
6
- as well as whether they should written to one file, multiple files, or
7
- just a list of strings (useful for streaming directly into a repl).
8
- Inspired by the Slick code generator albeit a bit simpler,
9
- the code generator is fairly customizeable and a couple of
10
- ready-to-use implementations come out of the box.
3
+ This library gives you a few options as to what kind of
4
+ schema to generate from JDBC metadata for Quill. You can choose to generate
5
+ simple case classes that are controlled entirely but a Quill Naming Strategy,
6
+ or a combination of case classes and ` querySchema ` s.
7
+ You can also choose whether they should written to one file, multiple files, or
8
+ just a list of strings (useful for executing directly into a repl).
9
+ Thanks to the Slick code generator creators for providing inspiration for this library!
11
10
12
11
Currently the code generator is only available for JDBC databases but it will
13
12
be extended in the future for Cassandra as well as others.
@@ -29,11 +28,11 @@ libraryDependencies += "io.getquill" %% "quill-codegen-jdbc" % "3.1.1-SNAPSHOT"
29
28
30
29
## SimpleJdbcCodegen
31
30
32
- This code generator is to generates simple case classes representing tables
31
+ This code generator generates simple case classes, each representing a table
33
32
in a database. It does not generate Quill ` querySchema ` objects.
34
33
Create one or multiple CodeGeneratorConfig objects
35
34
and call the ` .writeFiles ` or ` .writeStrings ` methods
36
- on the code generator and the rest happens automatically .
35
+ on the code generator to generate the code .
37
36
38
37
Given the following schema:
39
38
```` sql
@@ -64,8 +63,7 @@ gen.writeFiles("src/main/scala/com/my/project")
64
63
````
65
64
66
65
You can parse column and table names using either the ` SnakeCaseNames ` or the and the ` LiteralNames ` parser
67
- which are used with the respective Quill Naming Strategies. (For more complex naming rules, use the ` ComposeableTraitsJdbcCodegen `
68
- in order to generate ` querySchema ` object which can have fully customized column/table names).
66
+ which are used with the respective Quill Naming Strategies. They cannot be customized further with this code generator.
69
67
70
68
The following case case classes will be generated
71
69
```` scala
@@ -83,14 +81,15 @@ case class Address(personFk: Int, street: Option[String], zip: Option[Int])
83
81
````
84
82
85
83
86
- If you wish to generate schemas with custom table or column names, you need to use the ComposeableTraitsGen
87
- in order to generate your schemas.
84
+ If you wish to generate schemas with custom table or column names, you need to use the ` ComposeableTraitsJdbcCodegen `
85
+ in order to generate your schemas with ` querySchema ` objects .
88
86
89
87
## Composeable Traits Codegen
90
88
91
89
The ` ComposeableTraitsJdbcCodegen ` allows you to customize table/column names in entity case classes
92
- and generates the necessary ` querySchema ` object in order to map them. Additionally, it generates a
93
- database-independent query schema trait which can be composed with a ` Context ` object of your choice.
90
+ and generates the necessary ` querySchema ` object in order to map the fields.
91
+ Additionally, it generates a database-independent query schema trait which can be composed
92
+ with a ` Context ` object of your choice.
94
93
95
94
Given the following schema:
96
95
```` sql
@@ -168,8 +167,8 @@ object MyCustomContext extends SqlMirrorContext[H2Dialect, Literal](H2Dialect, L
168
167
169
168
## Stereotyping
170
169
Frequently in corporate databases, the same kind of table is duplicated across multiple schemas, databases, etc...
171
- for different business units. Typically, all the duplicates of the table will have almost the same columns
172
- with only minor differences. Stereotyped code-generation aims to take the 'lowest common denominator' of all these schemas
170
+ for different business units. Typically, all the duplicates of the table will have nearly the same columns
171
+ with just minor differences. Stereotyped code-generation aims to take the 'lowest common denominator' of all these schemas
173
172
in order to produce a case class that can be used across all of them.
174
173
175
174
Examine the following H2 DDL:
@@ -266,4 +265,4 @@ the `CommonExtensions` like so:
266
265
```` scala
267
266
object MyCustomContext extends SqlMirrorContext [H2Dialect , Literal ](H2Dialect , Literal )
268
267
with CommonExtensions [H2Dialect , Literal ]
269
- ````
268
+ ````
0 commit comments