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

infer_schema! fails when field is `type` and maybe other reserved Rust keywords #342

Closed
mkroman opened this Issue May 24, 2016 · 3 comments

Comments

Projects
None yet
4 participants
@mkroman

mkroman commented May 24, 2016

Hello.

When compiling with diesel, if a table has a field named type, the build will fail with the following error:

error: expected identifier, found keyword `type`
 --> <diesel macros>:5:52
5 |> table_body ! { $ name ( $ pk ) { $ ( $ column_name -> $ Type , ) + } } } ;
  |>

It's possible that this problem also exists for other Rust keywords.

A reasonable solution could be suffixing the Rust field with _ (i.e. type_) for reserved keywords.

@sgrif

This comment has been minimized.

Member

sgrif commented May 26, 2016

Yeah, for now there's no way to have columns with the same name as keywords in Rust. I'm planning on having some renaming convention in the future, but haven't decided on what it should be. The underscore proposal sounds reasonable.

@kardeiz

This comment has been minimized.

Contributor

kardeiz commented Jun 1, 2016

I think having a renaming convention would be a good idea for the infer_schema macro, but I think it would be nice to be able to explicitly specify the renaming/mapping using the table macro (something like column_name="type".

Also, note that the column_name field annotation for models also doesn't allow Rust keywords.

@Eijebong

This comment has been minimized.

Member

Eijebong commented Aug 24, 2017

Fixed by #1084 and #1110

@Eijebong Eijebong closed this Aug 24, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment