forked from sqlc-dev/sqlc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
internal/codegen: add Enum.Valid and AllEnumValues
This commit adds a Valid method for enum types and an All...Values function to get all enum values. This makes it easier to work with enums. These are gated by new config parameters emit_enum_valid_method and emit_all_enum_values. Fixes sqlc-dev#1607
- Loading branch information
Showing
15 changed files
with
432 additions
and
111 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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
32 changes: 32 additions & 0 deletions
32
internal/endtoend/testdata/emit_enum_valid_and_values/go/db.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
52 changes: 52 additions & 0 deletions
52
internal/endtoend/testdata/emit_enum_valid_and_values/go/models.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
70 changes: 70 additions & 0 deletions
70
internal/endtoend/testdata/emit_enum_valid_and_values/go/query.sql.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
12 changes: 12 additions & 0 deletions
12
internal/endtoend/testdata/emit_enum_valid_and_values/query.sql
This file contains 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,12 @@ | ||
CREATE TYPE ip_protocol AS enum ('tcp', 'ip', 'icmp'); | ||
|
||
CREATE TABLE bar_old (id_old serial not null, ip_old ip_protocol NOT NULL); | ||
|
||
-- name: ListFoo :many | ||
SELECT id_old as foo_old, id_old as baz_old | ||
FROM bar_old | ||
WHERE ip_old = $1 AND id_old = $2; | ||
|
||
-- name: ListBar :many | ||
SELECT * FROM bar_old; | ||
|
22 changes: 22 additions & 0 deletions
22
internal/endtoend/testdata/emit_enum_valid_and_values/sqlc.json
This file contains 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,22 @@ | ||
{ | ||
"version": "1", | ||
"packages": [ | ||
{ | ||
"path": "go", | ||
"engine": "postgresql", | ||
"sql_package": "pgx/v4", | ||
"name": "querytest", | ||
"schema": "query.sql", | ||
"queries": "query.sql", | ||
"emit_enum_valid_method": true, | ||
"emit_all_enum_values": true | ||
} | ||
], | ||
"rename": { | ||
"id_old": "IDNew", | ||
"bar_old": "BarNew", | ||
"foo_old": "FooNew", | ||
"ip_protocol": "IPProtocol", | ||
"ip_protocol_tcp": "IPProtocolTCP" | ||
} | ||
} |
Oops, something went wrong.