jet
jet copied to clipboard
Postgres Enum Support
Describe the bug Code generation fails for Postgres Enums.
--
-- Name: task_type; Type: TYPE; Schema: tasks; Owner: -
--
CREATE TYPE tasks.task_type AS ENUM (
'S3:INIT',
'PCAP:MERGE',
'CTRL:SUBMIT',
'CTRL:STOP'
);
CREATE TABLE tasks.task (
task_id bigint NOT NULL,
task_reference text,
context_id smallint,
task_type tasks.task_type NOT NULL,
task_status tasks.task_status NOT NULL,
creation_date timestamp with time zone DEFAULT now() NOT NULL,
last_modified timestamp with time zone DEFAULT now() NOT NULL,
task_data jsonb DEFAULT '{}'::jsonb,
CONSTRAINT referencechk CHECK ((char_length(task_reference) <= 20))
);
jet -dsn="postgresql://ht_controller_user:secret@localhost:5432/funcap_controller?sslmode=disable" -schema=tasks -path=./.gen Connecting to postgres database... Retrieving schema information... FOUND 2 table(s), 0 view(s), 2 enum(s) Destination directory: .gen/funcap_controller/tasks Cleaning up destination directory... Generating table model files... Generating enum model files... Error trace:
- failed to generate schema tasks:
- &{%!d(string=failed to generate model types:
- failed to process enum types:
- failed to save 'task_type' enum type:
- failed to format 'task_type', check '.gen/funcap_controller/tasks/model/task_type.go' for syntax errors:
- 16:13:
- expected ';', found ':' (and 3 more errors)) 1374391779904}
**Environment (please complete the following information):**
- OS: [e.g. linux, windows, macosx]
- Database: [e.g. postgres, mysql, sqlite]
- Database driver: [e.g. pq, pgx]
- Jet version [e.g. 2.6.0 or branch name]
**Code snippet**
Generated Code:
```go
const (
TaskType_S3:init TaskType = "S3:INIT"
TaskType_Pcap:merge TaskType = "PCAP:MERGE"
TaskType_Ctrl:submit TaskType = "CTRL:SUBMIT"
TaskType_Ctrl:stop TaskType = "CTRL:STOP"
)
Obviously this fails as it's invalid Go syntax.
Expected behavior The code to actually generate without errors.
You can customize the generator, and replace : character with a character of your choosing.
https://github.com/go-jet/jet/wiki/Generator#generator-customization
You can customize the generator, and replace
:character with a character of your choosing. https://github.com/go-jet/jet/wiki/Generator#generator-customization
I'm assuming that the only way to do this, is if you invoke the Generator from code?
I've made a quick fix for this bug on bug290 branch. Special characters are removed from go identifiers.
Sounds good, thank you!
I've changed my mind on this one. There were couple of bugs opened before for similar invalid character issues. To prevent any additional bugs from opening, I've made a change on master that does not remove but replaces all invalid ascii characters with the description.
So in your case, it would be S3ColonInit for S3:Init enum value.
That seems like a perfectly reasonable change. Thanks for the update.
Fixed in Release v2.11.0.