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

Support database schemas with spaces and dashes #2173

Closed

Conversation

zoewithabang
Copy link
Contributor

Closes #2168

I had a few issues in setting up my environment this weekend to be able to properly test the functionality past the unit test so I took a few assumptions on where sql names would be used over rust variable names (e.g. in joinable! and allow_tables_to_appear_in_same_query!).

Let me know if they need to be changed or if there are any other changes needed to complete this PR, thanks.

@weiznich weiznich requested a review from a team September 22, 2019 13:59
Copy link
Member

@weiznich weiznich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this. I've left some comments.
Additionally I would like to see a test case that uses a reserved keyword as table name.
Beside of that: Should we do the same thing also for table schemas?

diesel_cli/src/infer_schema_internals/table_data.rs Outdated Show resolved Hide resolved
diesel_cli/src/infer_schema_internals/inference.rs Outdated Show resolved Hide resolved
diesel_cli/src/infer_schema_internals/table_data.rs Outdated Show resolved Hide resolved
diesel_cli/src/print_schema.rs Outdated Show resolved Hide resolved
diesel_cli/src/print_schema.rs Show resolved Hide resolved
diesel_cli/tests/print_schema.rs Outdated Show resolved Hide resolved
@zoewithabang
Copy link
Contributor Author

Sorry for taking a while to get back to this, real life has been hitting me hard this month. 🙂

I had a look at doing the same for table schemas but was a bit unsure how to go about implementing it. If you think it's worth getting that in with this PR as well then I can have another go at it, any pointers would definitely help! 😄

Copy link
Member

@weiznich weiznich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now I needed some time for other stuff 🙈
Anyway the PR looks quite good now, I've found only a few minor things where the code could be improved.

diesel_cli/src/print_schema.rs Outdated Show resolved Hide resolved
diesel_cli/src/print_schema.rs Outdated Show resolved Hide resolved
diesel_cli/src/infer_schema_internals/table_data.rs Outdated Show resolved Hide resolved
@@ -14,7 +14,9 @@ static RESERVED_NAMES: &[&str] = &[
"type", "typeof", "unsafe", "unsized", "use", "virtual", "where", "while", "yield",
];

fn is_reserved(name: &str) -> bool {
static UNMAPPABLE_CHARS: &[char] = &['-', ' '];
Copy link
Contributor

@abreis abreis Mar 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SQL table names can use other characters that would not translate well to a Rust identifier (e.g., a colon :).

Rust identifiers are restricted to [a-z A-Z 0-9 _], so I think that a more robust approach would be to map any character outside of this range to an underscore.

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.

Generated schema fails to compile when tables and field names contain spaces
3 participants