Skip to content

Commit

Permalink
docs: Add documentation for codegen plugins (sqlc-dev#1904)
Browse files Browse the repository at this point in the history
  • Loading branch information
kyleconroy authored and akutschera committed Nov 10, 2022
1 parent e052241 commit 6df07e0
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 5 deletions.
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

0 comments on commit 6df07e0

Please sign in to comment.