|
1 | 1 | # Authoring plugins
|
2 | 2 |
|
| 3 | +To use plugins, you must be using [Version 2](../reference/config.html) of |
| 4 | +the configuration file. The top-level `plugins` array defines the available |
| 5 | +plugins. |
| 6 | + |
| 7 | +## WASM plugins |
| 8 | + |
| 9 | +> WASM plugins are fully sandboxed. Plugins do not have access to the network, |
| 10 | +> filesystem, or environment variables. |
| 11 | +
|
| 12 | +In the `codegen` section, the `out` field dictates what directory will contain |
| 13 | +the new files. The `plugin` key must reference a plugin defined in the |
| 14 | +top-level `plugins` map. The `options` are serialized to a string and passed on |
| 15 | +to the plugin itself. |
| 16 | + |
| 17 | + |
| 18 | +```json |
| 19 | +{ |
| 20 | + "version": "2", |
| 21 | + "plugins": [ |
| 22 | + { |
| 23 | + "name": "greeter", |
| 24 | + "wasm": { |
| 25 | + "url": "https://github.com/kyleconroy/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 | +} |
| 44 | +``` |
| 45 | + |
| 46 | +For a complete working example see the following files: |
| 47 | +- [sqlc-gen-greeter](https://github.com/kyleconroy/sqlc-gen-greeter) |
| 48 | + - A WASM plugin (written in Rust) that outputs a friendly message |
| 49 | +- [wasm_plugin_sqlc_gen_greeter](https://github.com/kyleconroy/sqlc/tree/main/internal/endtoend/testdata/wasm_plugin_sqlc_gen_greeter) |
| 50 | + - An example project showing how to use a WASM plugin |
| 51 | + |
3 | 52 | ## Process plugins
|
4 | 53 |
|
5 |
| -To use process-based plugins, you must be using [Version |
6 |
| -2](../reference/config.html) of the configuration file. The top-level `plugins` |
7 |
| -array defines the available plugins and maps them to an executable on the system. |
| 54 | +> Process-based plugins offer minimal security. Only use plugins that you |
| 55 | +> trust. Better yet, only use plugins that you've written yourself. |
8 | 56 |
|
9 | 57 | In the `codegen` section, the `out` field dictates what directory will contain
|
10 | 58 | the new files. The `plugin` key must reference a plugin defined in the
|
@@ -47,12 +95,3 @@ For a complete working example see the following files:
|
47 | 95 | - A process-based plugin that serializes the CodeGenRequest to JSON
|
48 | 96 | - [process_plugin_sqlc_gen_json](https://github.com/kyleconroy/sqlc/tree/main/internal/endtoend/testdata/process_plugin_sqlc_gen_json)
|
49 | 97 | - An example project showing how to use a process-based plugin
|
50 |
| - |
51 |
| -### Security |
52 |
| - |
53 |
| -Process-based plugins offer minimal security. Only use plugins that you trust. |
54 |
| -Better yet, only use plugins that you've written yourself. |
55 |
| - |
56 |
| -## WASM plugins |
57 |
| - |
58 |
| -*Coming soon!* |
|
0 commit comments