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

sea-orm-cli generates invalid code when table name is a Rust keyword #1051

Closed
andy128k opened this issue Sep 18, 2022 · 1 comment · Fixed by #1052
Closed

sea-orm-cli generates invalid code when table name is a Rust keyword #1051

andy128k opened this issue Sep 18, 2022 · 1 comment · Fixed by #1052
Assignees
Milestone

Comments

@andy128k
Copy link
Contributor

andy128k commented Sep 18, 2022

Description

I have a database with a table named type. When I run sea-orm-cli it generates syntactically invalid code.

  • mod type; should be mod r#type;
  • use crate::type::Entity should be use crate::r#type::Entity

Steps to Reproduce

  1. create a database with a table named type (probably any rust keyword gives the same resull)
  2. cargo new bug ; cd bug
  3. sea-orm-cli generate entity -u mysql://user:pw@localhost/db -o entity/src

Expected Behavior

Generated code should be valid.

Actual Behavior

Generated code does not compile.

error: expected identifier, found keyword `type`
  --> /.../entity/src/mod.rs:36:9
   |
36 | pub mod type ;
   |         ^^^^ expected identifier, found keyword
   |
help: escape `type` to use it as an identifier
   |
36 | pub mod r#type ;
   |         ++

error: expected identifier, found keyword `type`
  --> /.../entity/src/prelude.rs:34:18
   |
34 | pub use super :: type :: Entity as Type ;
   |                  ^^^^ expected identifier, found keyword
   |
help: escape `type` to use it as an identifier
   |
34 | pub use super :: r#type :: Entity as Type ;
   |                  ++

Reproduces How Often

Always

Versions

├── sea-orm v0.9.2
│   ├── sea-orm-macros v0.9.2 (proc-macro)
│   ├── sea-query v0.26.3
│   │   ├── sea-query-derive v0.2.0 (proc-macro)
│   │   ├── sea-query-driver v0.2.2 (proc-macro)
│   ├── sea-strum v0.23.0
│   │   └── sea-strum_macros v0.23.0 (proc-macro)
│   ├── sea-orm v0.9.2 (*)

Additional Information

It seems like code generated by DeriveRelation macro also has this issue.

@billy1624 billy1624 moved this to Triage in SeaQL Dev Tracker Sep 20, 2022
@billy1624 billy1624 moved this from Triage to Changes / Comments Requested in SeaQL Dev Tracker Sep 20, 2022
@billy1624
Copy link
Member

Hey @andy128k, thanks for the report! Please check #1052 (review)

@billy1624 billy1624 added this to the 0.10.x milestone Oct 26, 2022
@billy1624 billy1624 moved this from Changes / Comments Requested to Done in SeaQL Dev Tracker Jan 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants