Skip to content

docs: Add documentation for codegen plugins #1904

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 55 additions & 4 deletions docs/reference/config.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Configuration

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

## Version 2

Expand Down Expand Up @@ -34,10 +34,44 @@ Each mapping in the `sql` collection has the following keys:
- Directory of SQL migrations or path to single SQL file; or a list of paths.
- `queries`:
- Directory of SQL queries or path to single SQL file; or a list of paths.
- `codegen`:
- A colleciton of mappings to configure code generators. See [codegen](#codegen) for the supported keys.
- `gen`:
- A mapping to configure built-in code generators. See [gen](#gen) for the supported keys.
- `strict_function_checks`
- If true, return an error if a called SQL function does not exist. Defaults to `false`.
-
### codegen

The `codegen` mapping supports the following keys:

- `out`:
- Output directory for generated code.
- `plugin`:
- The name of the plugin. Must be defined in the `plugins` collection.
- `options`:
- A mapping of plugin-specific options.

```yaml
version: '2'
plugins:
- name: py
wasm:
url: https://github.com/tabbed/sqlc-gen-python/releases/download/v0.16.0-alpha/sqlc-gen-python.wasm
sha256: 428476c7408fd4c032da4ec74e8a7344f4fa75e0f98a5a3302f238283b9b95f2
sql:
- schema: "schema.sql"
queries: "query.sql"
engine: postgresql
codegen:
- out: src/authors
plugin: py
options:
package: authors
emit_sync_querier: true
emit_async_querier: true
query_parameter_limit: 5
```

### gen

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

- `name`:
- The name of this plugin. Required
- `process`:
- `process`: A mapping with a single `cmd` key
- `cmd`:
- The executable to call when using this plugin

- `wasm`: A mapping with a two keys `url` and `sha256`
- `url`:
- The URL to fetch the WASM file. Supports the `https://` or `file://` schemes.
- `sha256`
- The SHA256 checksum for the downloaded file.

```yaml
version: 2
plugins:
- name: "py"
wasm:
url: "https://github.com/tabbed/sqlc-gen-python/releases/download/v0.16.0-alpha/sqlc-gen-python.wasm"
sha256: "428476c7408fd4c032da4ec74e8a7344f4fa75e0f98a5a3302f238283b9b95f2"
- name: "js"
process:
cmd: "sqlc-gen-json"
```

### global overrides

Sometimes, the same configuration must be done across various specfications of code generation.
Expand Down
2 changes: 1 addition & 1 deletion examples/python/sqlc.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"wasm": {
"url": "https://github.com/tabbed/sqlc-gen-python/releases/download/v0.16.0-alpha/sqlc-gen-python.wasm",
"sha256": "428476c7408fd4c032da4ec74e8a7344f4fa75e0f98a5a3302f238283b9b95f2"
},
}
}
],
"sql": [
Expand Down