Skip to content

Commit 12e7cd9

Browse files
committed
more docs
1 parent fb88b7f commit 12e7cd9

File tree

2 files changed

+59
-55
lines changed

2 files changed

+59
-55
lines changed

docs/guides/plugins.md

Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -15,32 +15,20 @@ top-level `plugins` map. The `options` are serialized to a string and passed on
1515
to the plugin itself.
1616

1717

18-
```json
19-
{
20-
"version": "2",
21-
"plugins": [
22-
{
23-
"name": "greeter",
24-
"wasm": {
25-
"url": "https://github.com/sqlc-dev/sqlc-gen-greeter/releases/download/v0.1.0/sqlc-gen-greeter.wasm",
26-
"sha256": "afc486dac2068d741d7a4110146559d12a013fd0286f42a2fc7dcd802424ad07"
27-
}
28-
}
29-
],
30-
"sql": [
31-
{
32-
"schema": "schema.sql",
33-
"queries": "query.sql",
34-
"engine": "postgresql",
35-
"codegen": [
36-
{
37-
"out": "gen",
38-
"plugin": "greeter"
39-
}
40-
]
41-
}
42-
]
43-
}
18+
```yaml
19+
version: '2'
20+
plugins:
21+
- name: greeter
22+
wasm:
23+
url: https://github.com/sqlc-dev/sqlc-gen-greeter/releases/download/v0.1.0/sqlc-gen-greeter.wasm
24+
sha256: afc486dac2068d741d7a4110146559d12a013fd0286f42a2fc7dcd802424ad07
25+
sql:
26+
- schema: schema.sql
27+
queries: query.sql
28+
engine: postgresql
29+
codegen:
30+
- out: gen
31+
plugin: greeter
4432
```
4533
4634
For a complete working example see the following files:
@@ -59,39 +47,51 @@ the new files. The `plugin` key must reference a plugin defined in the
5947
top-level `plugins` map. The `options` are serialized to a string and passed on
6048
to the plugin itself.
6149

62-
```json
63-
{
64-
"version": "2",
65-
"plugins": [
66-
{
67-
"name": "jsonb",
68-
"process": {
69-
"cmd": "sqlc-gen-json"
70-
}
71-
}
72-
],
73-
"sql": [
74-
{
75-
"schema": "schema.sql",
76-
"queries": "query.sql",
77-
"engine": "postgresql",
78-
"codegen": [
79-
{
80-
"out": "gen",
81-
"plugin": "jsonb",
82-
"options": {
83-
"indent": " ",
84-
"filename": "codegen.json"
85-
}
86-
}
87-
]
88-
}
89-
]
90-
}
50+
```yaml
51+
version: '2'
52+
plugins:
53+
- name: jsonb
54+
process:
55+
cmd: sqlc-gen-json
56+
sql:
57+
- schema: schema.sql
58+
queries: query.sql
59+
engine: postgresql
60+
codegen:
61+
- out: gen
62+
plugin: jsonb
63+
options:
64+
indent: " "
65+
filename: codegen.json
9166
```
9267

9368
For a complete working example see the following files:
9469
- [sqlc-gen-json](https://github.com/sqlc-dev/sqlc/tree/main/cmd/sqlc-gen-json)
9570
- A process-based plugin that serializes the CodeGenRequest to JSON
9671
- [process_plugin_sqlc_gen_json](https://github.com/sqlc-dev/sqlc/tree/main/internal/endtoend/testdata/process_plugin_sqlc_gen_json)
9772
- An example project showing how to use a process-based plugin
73+
74+
## Environment variables
75+
76+
By default, plugins do not inherit access to environment variables. Instead,
77+
access can be configured on a per-variable basis. For example, if your plugin
78+
needs the `PATH` environment variable, add the `PATH` to the `env` option in the
79+
`plugins` collection.
80+
81+
```yaml
82+
version: '2'
83+
sql:
84+
- schema: schema.sql
85+
queries: query.sql
86+
engine: postgresql
87+
codegen:
88+
- out: gen
89+
plugin: test
90+
plugins:
91+
- name: test
92+
env:
93+
- PATH
94+
wasm:
95+
url: https://github.com/sqlc-dev/sqlc-gen-test/releases/download/v0.1.0/sqlc-gen-test.wasm
96+
sha256: 138220eae508d4b65a5a8cea555edd155eb2290daf576b7a8b96949acfeb3790
97+
```

docs/reference/config.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,8 @@ Each mapping in the `plugins` collection has the following keys:
316316

317317
- `name`:
318318
- The name of this plugin. Required
319+
- `env`
320+
- A list of environment variables to pass to the plugin. By default, no environment variables are passed.
319321
- `process`: A mapping with a single `cmd` key
320322
- `cmd`:
321323
- The executable to call when using this plugin
@@ -333,6 +335,8 @@ plugins:
333335
url: "https://github.com/sqlc-dev/sqlc-gen-python/releases/download/v0.16.0-alpha/sqlc-gen-python.wasm"
334336
sha256: "428476c7408fd4c032da4ec74e8a7344f4fa75e0f98a5a3302f238283b9b95f2"
335337
- name: "js"
338+
env:
339+
- PATH
336340
process:
337341
cmd: "sqlc-gen-json"
338342
```

0 commit comments

Comments
 (0)