-
Notifications
You must be signed in to change notification settings - Fork 881
feat(codegen): Allow plugins to access environment variables #2669
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
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
686da14
feat(codegen): Allow plugins to access environment variables
kyleconroy c1ce837
Add tests for process-based plugins
kyleconroy 25f9ce1
chore: Move sqlc-gen-env to a different repo
kyleconroy e926e9d
change test out
kyleconroy fb88b7f
Test both WASM and process-based
kyleconroy 12e7cd9
more docs
kyleconroy d4e5fde
Add SQLC_VERSION to docs
kyleconroy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -316,6 +316,8 @@ Each mapping in the `plugins` collection has the following keys: | |
|
||
- `name`: | ||
- The name of this plugin. Required | ||
- `env` | ||
- A list of environment variables to pass to the plugin. By default, no environment variables are passed. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is the |
||
- `process`: A mapping with a single `cmd` key | ||
- `cmd`: | ||
- The executable to call when using this plugin | ||
|
@@ -333,6 +335,8 @@ plugins: | |
url: "https://github.com/sqlc-dev/sqlc-gen-python/releases/download/v0.16.0-alpha/sqlc-gen-python.wasm" | ||
sha256: "428476c7408fd4c032da4ec74e8a7344f4fa75e0f98a5a3302f238283b9b95f2" | ||
- name: "js" | ||
env: | ||
- PATH | ||
process: | ||
cmd: "sqlc-gen-json" | ||
``` | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
internal/endtoend/testdata/process_plugin_sqlc_gen_test/exec.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"process": "sqlc-gen-test" | ||
} |
6 changes: 6 additions & 0 deletions
6
internal/endtoend/testdata/process_plugin_sqlc_gen_test/gen/env.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"env": [ | ||
"SQLC_VERSION=v1.20.0", | ||
"SQLC_DUMMY_VALUE=true" | ||
] | ||
} |
19 changes: 19 additions & 0 deletions
19
internal/endtoend/testdata/process_plugin_sqlc_gen_test/query.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
-- name: GetAuthor :one | ||
SELECT * FROM authors | ||
WHERE id = $1 LIMIT 1; | ||
|
||
-- name: ListAuthors :many | ||
SELECT * FROM authors | ||
ORDER BY name; | ||
|
||
-- name: CreateAuthor :one | ||
INSERT INTO authors ( | ||
name, bio | ||
) VALUES ( | ||
$1, $2 | ||
) | ||
RETURNING *; | ||
|
||
-- name: DeleteAuthor :exec | ||
DELETE FROM authors | ||
WHERE id = $1; |
5 changes: 5 additions & 0 deletions
5
internal/endtoend/testdata/process_plugin_sqlc_gen_test/schema.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
CREATE TABLE authors ( | ||
id BIGSERIAL PRIMARY KEY, | ||
name text NOT NULL, | ||
bio text | ||
); |
25 changes: 25 additions & 0 deletions
25
internal/endtoend/testdata/process_plugin_sqlc_gen_test/sqlc.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"version": "2", | ||
"sql": [ | ||
{ | ||
"schema": "schema.sql", | ||
"queries": "query.sql", | ||
"engine": "postgresql", | ||
"codegen": [ | ||
{ | ||
"out": "gen", | ||
"plugin": "test" | ||
} | ||
] | ||
} | ||
], | ||
"plugins": [ | ||
{ | ||
"name": "test", | ||
"env": ["SQLC_DUMMY_VALUE"], | ||
"process": { | ||
"cmd": "sqlc-gen-test" | ||
} | ||
} | ||
] | ||
} |
6 changes: 6 additions & 0 deletions
6
internal/endtoend/testdata/wasm_plugin_sqlc_gen_test/gen/env.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"env": [ | ||
"SQLC_VERSION=v1.20.0", | ||
"SQLC_DUMMY_VALUE=true" | ||
] | ||
} |
19 changes: 19 additions & 0 deletions
19
internal/endtoend/testdata/wasm_plugin_sqlc_gen_test/query.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
-- name: GetAuthor :one | ||
SELECT * FROM authors | ||
WHERE id = $1 LIMIT 1; | ||
|
||
-- name: ListAuthors :many | ||
SELECT * FROM authors | ||
ORDER BY name; | ||
|
||
-- name: CreateAuthor :one | ||
INSERT INTO authors ( | ||
name, bio | ||
) VALUES ( | ||
$1, $2 | ||
) | ||
RETURNING *; | ||
|
||
-- name: DeleteAuthor :exec | ||
DELETE FROM authors | ||
WHERE id = $1; |
5 changes: 5 additions & 0 deletions
5
internal/endtoend/testdata/wasm_plugin_sqlc_gen_test/schema.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
CREATE TABLE authors ( | ||
id BIGSERIAL PRIMARY KEY, | ||
name text NOT NULL, | ||
bio text | ||
); |
26 changes: 26 additions & 0 deletions
26
internal/endtoend/testdata/wasm_plugin_sqlc_gen_test/sqlc.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"version": "2", | ||
"sql": [ | ||
{ | ||
"schema": "schema.sql", | ||
"queries": "query.sql", | ||
"engine": "postgresql", | ||
"codegen": [ | ||
{ | ||
"out": "gen", | ||
"plugin": "test" | ||
} | ||
] | ||
} | ||
], | ||
"plugins": [ | ||
{ | ||
"name": "test", | ||
"env": ["SQLC_DUMMY_VALUE"], | ||
"wasm": { | ||
"url": "https://github.com/sqlc-dev/sqlc-gen-test/releases/download/v0.1.0/sqlc-gen-test.wasm", | ||
"sha256": "138220eae508d4b65a5a8cea555edd155eb2290daf576b7a8b96949acfeb3790" | ||
} | ||
} | ||
] | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.