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

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

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

Comments

@mkroman
Copy link

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
Copy link
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
Copy link
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
Copy link
Member

Fixed by #1084 and #1110

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

No branches or pull requests

4 participants