cornucopia-rs / cornucopia

Generate type-checked Rust from your PostgreSQL.
Other
759 stars 31 forks source link

[Bug] Edge case for Postgres Enum Support - Postgres Enums with special characters (e.g. space) #194

Closed rconnol closed 1 year ago

rconnol commented 1 year ago
create type season_type as enum ('Regular Season', 'Playoffs', 'Pre Season', 'All Star');

create table seasons
(
    season_id   integer                 not null,
    league_id   smallint                not null,
    season_name varchar                 not null,
    season_type season_type             not null,
    updated_at  timestamp default now() not null,
    created_at  timestamp default now() not null,
    primary key (season_id, league_id)
);

I have a table with a custom postgres enum defined. I defined the enum using the human readable spellings of the SeasonType values.

When I generate the code with cornucopia, the generated Rust code is invalid... and I get the following error:

error: expected one of `(`, `,`, `=`, `{`, or `}`, found `Season`
 --> bucket-list-etl/src/cornucopia.rs:5:62
  |
5 | #[allow(non_camel_case_types)] pub enum SeasonType { Regular Season,Playoffs,Pre Season,All Star,}impl < 'a > postgres_types :: ToSql for...
  |                                                             -^^^^^^ expected one of `(`, `,`, `=`, `{`, or `}`
  |                                                             |
  |                                                             help: missing `,`

My hunch is that other valid special characters like "dashes", might cause a similar issue.

Virgiel commented 1 year ago

Will be fixed by #185

LouisGariepy commented 1 year ago

@rconnol this should be fixed by #185 now that it has been merged!

Thanks for reporting the issue, please let us know if there's still a problem.

Cheers :smile: