-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Allow raw identifiers for SqlIdentifier (column-name) #4030
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for opening this PR. I think the change itself looks fine, but we want to have some tests that show that everything is parsed correctly.
Sure. I added it for the |
3240f29
to
5822c30
Compare
I think I would prefer to have these kind of test for |
e925fd9
to
bd2a6eb
Compare
Alright, I added raw identifiers to the respective test cases. |
No worries about the force pushes, that's fine. For the spell checker: You can just add an exception here: https://github.com/diesel-rs/diesel/blob/master/.typos.toml#L8 As for running the tests: There is a bash script in |
Ah thanks, that works. |
} | ||
|
||
let conn = &mut connection(); | ||
let data = sql_query("SELECT 1 AS foo, 2 AS bar").get_result(conn); | ||
assert_eq!(Ok(MyStruct { foo: 1, bar: 2 }), data); | ||
let data = sql_query("SELECT 1 AS foo, 2 AS bar, 3 AS `r#type`").get_result(conn); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
QueryableByName perhaps poses an interesting question. Should the query indeed contain `r#type`
to match or should the SQL query contain type
and map to the raw identifier r#type
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would expect type
there.
dcef510
to
65a1dcb
Compare
let conn = &mut connection(); | ||
let data = sql_query("SELECT 1 AS foo, 2 AS bar").get_result(conn); | ||
let data = sql_query("SELECT 1 AS foo, 2 AS bar, 3 AS \"r#type\"").get_result(conn); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like the above QueryableByName should try to read type
, not r#type
.
); | ||
|
||
let conn = &mut connection(); | ||
let data = sql_query("SELECT 1 AS foo, 2 AS bar").get_result(conn); | ||
assert_eq!(Ok(MyStruct(1, 2)), data); | ||
let data = sql_query("SELECT 1 AS foo, 2 AS bar, 3 AS \"r#type\"").get_result(conn); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think to be consistent with previous comment we probably should search for type
as name if passing the r#type
ident
and ideally also allow passing column_name = "some arbitrary string"
where we would then parse 3 as "some arbitrary string"
even if some arbitrary string
is not an ident to support other weird things users might want. (I'm not sure if that is already supported and it's not a blocker here)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have lifted the restriction on column_name
insofar, that a raw identifier is now allowed, however it must still correspond to a valid Rust identifier.
The previous error-message for invalid names is retained, though it now emits an unhelpful
error: Expected valid identifier, found `ty pe`. Diesel automatically renames invalid identifiers, perhaps you meant to write `ty pe_`?
--> diesel_derives/tests/as_changeset.rs:287:32
|
287 | #[diesel(column_name = "ty pe")]
| ^^^^^^^
The error-message should probably use inference::rust_name_for_sql_name()
?
113b6b5
to
365660d
Compare
This allows using the `r#identifier` syntax for SqlIdentifier (column-name), which is used in derive macros. Previously the derive macros would panic when encountering such an identifier: `"r#identifier"` is not a valid identifier
e846ad4
to
5a044a6
Compare
This allows using the
r#identifier
syntax for SqlIdentifier (column-name), which is used in derive macros.Previously the derive macros would panic when encountering such an identifier: