Skip to content
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

fix: Escape enum members containing reserved keywords #159

Closed

Conversation

jacobsvante
Copy link
Contributor

Just stumbled upon an issue where one of the enum members of an existing postgres enum was box. Cornucopia happily generated the cornucopia.rs file, but the result was a file with a syntax error in it.

So here comes my quick-fix to that.

This PR is not meant to be merged, just demonstrating one way to resolve the issue. I'm a bit short on time so if anyone with more intimate knowledge of the codebase wants to do it properly, then please go ahead 😉

@jacobsvante
Copy link
Contributor Author

#[allow(non_camel_case_types)] needs to be added to pub mod types, to avoid warnings.

@jacobsvante
Copy link
Contributor Author

jacobsvante commented Sep 23, 2022

Hmmm. It seems that postgres/tokio-postgres does not like enums with raw identifiers. Gives me the following error when I try to execute a SELECT with the given column included:

thread 'main' panicked at 'error retrieving column 9: error deserializing column 9: cannot convert between
the Rust type `data_import::cornucopia::types::public::Uom` and the Postgres type `uom`',
/Users/jacob/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-postgres-0.7.7/src/row.rs:151:25

The enum looks like this:

        pub enum Uom {
            pair,
            pcs,
            r#box,
        }

If I do ALTER TYPE uom RENAME VALUE 'box' TO 'Box' and re-run cornucopia, the issue disappears.

@Virgiel

This comment was marked as outdated.

@jacobsvante
Copy link
Contributor Author

Replaced by more thorough version in #161

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants