Skip to content

Commit ae66700

Browse files
authored
docs: Add documentation for version 2 of the configuration file (#1657)
1 parent b0d6f13 commit ae66700

File tree

1 file changed

+121
-6
lines changed

1 file changed

+121
-6
lines changed

docs/reference/config.md

Lines changed: 121 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,123 @@
1-
# Configuration file (version 1)
1+
# Configuration
22

33
The `sqlc` tool is configured via a `sqlc.yaml` or `sqlc.json` file. This file must be
44
in the directory where the `sqlc` command is run.
55

6+
## Version 2
7+
8+
```yaml
9+
version: "2"
10+
sql:
11+
- schema: "postgresql/schema.sql"
12+
queries: "postgresql/query.sql"
13+
engine: "postgresql"
14+
gen:
15+
go:
16+
package: "authors"
17+
out: "postgresql"
18+
- schema: "mysql/schema.sql"
19+
queries: "mysql/query.sql"
20+
engine: "mysql"
21+
gen:
22+
go:
23+
package: "authors"
24+
out: "mysql
25+
```
26+
27+
Each mapping in the `sql` collection has the following keys:
28+
29+
- `engine`:
30+
- Either `postgresql` or `mysql`.
31+
- `schema`:
32+
- Directory of SQL migrations or path to single SQL file; or a list of paths.
33+
- `queries`:
34+
- Directory of SQL queries or path to single SQL file; or a list of paths.
35+
- `gen`:
36+
- A mapping to configure built-in code generators. Supports the following keys:
37+
- `go`:
38+
- Go code generation options
39+
- `kotlin`:
40+
- Kotlin code generation options
41+
- `python`:
42+
- Python code generation options
43+
- `json`:
44+
- JSON output options
45+
- `strict_function_checks`
46+
- If true, return an error if a called SQL function does not exist. Defaults to `false`.
47+
48+
### go
49+
50+
- `package`:
51+
- The package name to use for the generated code. Defaults to `out` basename.
52+
- `out`:
53+
- Output directory for generated code.
54+
- `sql_package`:
55+
- Either `pgx/v4` or `database/sql`. Defaults to `database/sql`.
56+
- `emit_db_tags`:
57+
- If true, add DB tags to generated structs. Defaults to `false`.
58+
- `emit_prepared_queries`:
59+
- If true, include support for prepared queries. Defaults to `false`.
60+
- `emit_interface`:
61+
- If true, output a `Querier` interface in the generated package. Defaults to `false`.
62+
- `emit_exact_table_names`:
63+
- If true, struct names will mirror table names. Otherwise, sqlc attempts to singularize plural table names. Defaults to `false`.
64+
- `emit_empty_slices`:
65+
- If true, slices returned by `:many` queries will be empty instead of `nil`. Defaults to `false`.
66+
- `emit_exported_queries`:
67+
- If true, autogenerated SQL statement can be exported to be accessed by another package.
68+
- `emit_json_tags`:
69+
- If true, add JSON tags to generated structs. Defaults to `false`.
70+
- `emit_result_struct_pointers`:
71+
- If true, query results are returned as pointers to structs. Queries returning multiple results are returned as slices of pointers. Defaults to `false`.
72+
- `emit_params_struct_pointers`:
73+
- If true, parameters are passed as pointers to structs. Defaults to `false`.
74+
- `emit_methods_with_db_argument`:
75+
- If true, generated methods will accept a DBTX argument instead of storing a DBTX on the `*Queries` struct. Defaults to `false`.
76+
- `emit_enum_valid_method`:
77+
- If true, generate a Valid method on enum types,
78+
indicating whether a string is a valid enum value.
79+
- `emit_all_enum_values`:
80+
- If true, emit a function per enum type
81+
that returns all valid enum values.
82+
- `json_tags_case_style`:
83+
- `camel` for camelCase, `pascal` for PascalCase, `snake` for snake_case or `none` to use the column name in the DB. Defaults to `none`.
84+
- `output_db_file_name`:
85+
- Customize the name of the db file. Defaults to `db.go`.
86+
- `output_models_file_name`:
87+
- Customize the name of the models file. Defaults to `models.go`.
88+
- `output_querier_file_name`:
89+
- Customize the name of the querier file. Defaults to `querier.go`.
90+
- `output_files_suffix`:
91+
- If specified the suffix will be added to the name of the generated files.
92+
93+
### kotlin
94+
95+
- `package`:
96+
- The package name to use for the generated code.
97+
- `out`:
98+
- Output directory for generated code.
99+
- `emit_exact_table_names`:
100+
- If true, use the exact table name for generated models. Otherwise, guess a singular form. Defaults to `false`.
101+
102+
### python
103+
104+
- `package`:
105+
- The package name to use for the generated code.
106+
- `out`:
107+
- Output directory for generated code.
108+
- `emit_exact_table_names`:
109+
- If true, use the exact table name for generated models. Otherwise, guess a singular form. Defaults to `false`.
110+
- `emit_sync_querier`:
111+
- If true, generate a class with synchronous methods. Defaults to `false`.
112+
- `emit_async_querier`:
113+
- If true, generate a class with asynchronous methods. Defaults to `false`.
114+
- `emit_pydantic_models`:
115+
- If true, generate classes that inherit from `pydantic.BaseModel`. Otherwise, define classes using the `dataclass` decorator. Defaults to `false`.
116+
117+
### json
118+
119+
## Version 1
120+
6121
```yaml
7122
version: "1"
8123
packages:
@@ -28,16 +143,16 @@ packages:
28143
output_querier_file_name: "querier.go"
29144
```
30145
31-
Each package document has the following keys:
146+
Each mapping in the `packages` collection has the following keys:
32147

33148
- `name`:
34-
- The package name to use for the generated code. Defaults to `path` basename
149+
- The package name to use for the generated code. Defaults to `path` basename.
35150
- `path`:
36-
- Output directory for generated code
151+
- Output directory for generated code.
37152
- `queries`:
38-
- Directory of SQL queries or path to single SQL file; or a list of paths
153+
- Directory of SQL queries or path to single SQL file; or a list of paths.
39154
- `schema`:
40-
- Directory of SQL migrations or path to single SQL file; or a list of paths
155+
- Directory of SQL migrations or path to single SQL file; or a list of paths.
41156
- `engine`:
42157
- Either `postgresql` or `mysql`. Defaults to `postgresql`.
43158
- `sql_package`:

0 commit comments

Comments
 (0)