Skip to content

Commit 2cbcd1f

Browse files
authored
docs: Add documentation for codegen plugins (#1904)
1 parent ff3f03d commit 2cbcd1f

File tree

2 files changed

+56
-5
lines changed

2 files changed

+56
-5
lines changed

docs/reference/config.md

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Configuration
22

3-
The `sqlc` tool is configured via a `sqlc.yaml` or `sqlc.json` file. This file must be
4-
in the directory where the `sqlc` command is run.
3+
The `sqlc` tool is configured via a `sqlc.yaml` or `sqlc.json` file. This
4+
file must be in the directory where the `sqlc` command is run.
55

66
## Version 2
77

@@ -34,10 +34,44 @@ Each mapping in the `sql` collection has the following keys:
3434
- Directory of SQL migrations or path to single SQL file; or a list of paths.
3535
- `queries`:
3636
- Directory of SQL queries or path to single SQL file; or a list of paths.
37+
- `codegen`:
38+
- A colleciton of mappings to configure code generators. See [codegen](#codegen) for the supported keys.
3739
- `gen`:
3840
- A mapping to configure built-in code generators. See [gen](#gen) for the supported keys.
3941
- `strict_function_checks`
4042
- If true, return an error if a called SQL function does not exist. Defaults to `false`.
43+
-
44+
### codegen
45+
46+
The `codegen` mapping supports the following keys:
47+
48+
- `out`:
49+
- Output directory for generated code.
50+
- `plugin`:
51+
- The name of the plugin. Must be defined in the `plugins` collection.
52+
- `options`:
53+
- A mapping of plugin-specific options.
54+
55+
```yaml
56+
version: '2'
57+
plugins:
58+
- name: py
59+
wasm:
60+
url: https://github.com/tabbed/sqlc-gen-python/releases/download/v0.16.0-alpha/sqlc-gen-python.wasm
61+
sha256: 428476c7408fd4c032da4ec74e8a7344f4fa75e0f98a5a3302f238283b9b95f2
62+
sql:
63+
- schema: "schema.sql"
64+
queries: "query.sql"
65+
engine: postgresql
66+
codegen:
67+
- out: src/authors
68+
plugin: py
69+
options:
70+
package: authors
71+
emit_sync_querier: true
72+
emit_async_querier: true
73+
query_parameter_limit: 5
74+
```
4175

4276
### gen
4377

@@ -223,10 +257,27 @@ Each mapping in the `plugins` collection has the following keys:
223257

224258
- `name`:
225259
- The name of this plugin. Required
226-
- `process`:
260+
- `process`: A mapping with a single `cmd` key
227261
- `cmd`:
228262
- The executable to call when using this plugin
229-
263+
- `wasm`: A mapping with a two keys `url` and `sha256`
264+
- `url`:
265+
- The URL to fetch the WASM file. Supports the `https://` or `file://` schemes.
266+
- `sha256`
267+
- The SHA256 checksum for the downloaded file.
268+
269+
```yaml
270+
version: 2
271+
plugins:
272+
- name: "py"
273+
wasm:
274+
url: "https://github.com/tabbed/sqlc-gen-python/releases/download/v0.16.0-alpha/sqlc-gen-python.wasm"
275+
sha256: "428476c7408fd4c032da4ec74e8a7344f4fa75e0f98a5a3302f238283b9b95f2"
276+
- name: "js"
277+
process:
278+
cmd: "sqlc-gen-json"
279+
```
280+
230281
### global overrides
231282

232283
Sometimes, the same configuration must be done across various specfications of code generation.

examples/python/sqlc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"wasm": {
77
"url": "https://github.com/tabbed/sqlc-gen-python/releases/download/v0.16.0-alpha/sqlc-gen-python.wasm",
88
"sha256": "428476c7408fd4c032da4ec74e8a7344f4fa75e0f98a5a3302f238283b9b95f2"
9-
},
9+
}
1010
}
1111
],
1212
"sql": [

0 commit comments

Comments
 (0)