From 082317f051dfe678b1edcb2d56cb79762e34de18 Mon Sep 17 00:00:00 2001 From: Kyle Conroy Date: Tue, 18 Oct 2022 22:43:12 -0700 Subject: [PATCH] docs: Add documentation for codegen plugins --- docs/reference/config.md | 59 ++++++++++++++++++++++++++++++++++++--- examples/python/sqlc.json | 2 +- 2 files changed, 56 insertions(+), 5 deletions(-) diff --git a/docs/reference/config.md b/docs/reference/config.md index f9df3f31f2..5dddd4a7cf 100644 --- a/docs/reference/config.md +++ b/docs/reference/config.md @@ -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 @@ -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 @@ -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. diff --git a/examples/python/sqlc.json b/examples/python/sqlc.json index acc866b1c4..04ebe36b0f 100644 --- a/examples/python/sqlc.json +++ b/examples/python/sqlc.json @@ -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": [