-
-
Notifications
You must be signed in to change notification settings - Fork 194
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
Macro for generating the Iden from a given Struct #717
Comments
Hi there. Thank you for your suggestion. It may not be well-advertised, but do you think https://github.com/SeaQL/sea-query/blob/master/sea-query-attr/tests/pass/default.rs serves the need? one more example: https://github.com/SeaQL/sea-query#iden |
@tyt2y3 Definitely, totally my bad! Awesome that this feature already is implemented, totally missed that while I was checking the docs. |
I was about to say, the original contributor thinks it's more appropriate to make it an attribute macro instead of a derive macro, since it generates structs instead of implementing traits. So a possible improvement might be to make it work as a derive macro as well. This could possibly make the user code looks cleaner. |
Ahh, I see, then let's reopen the issue. |
Derive macros also support extra derive attributes. I think it's just a stylistic preference to the user. |
Motivation
Hi,
I am primarily using SQLx at the moment, but I did take a look at SeaQuery and would like to try it in a few places. However, for me, it produces some unnecessary boilerplate with the Iden when I am already using structs as my models. I understand that Iden is not really a replacement, but maintaining both an enum and a struct is not very efficient for me.
Is there any macro we can use to automatically generate the Iden enum definition for the struct? I'd prefer to use SeaQuery optionally in a few places where it's perfectly fine to have a "CompanyIden" enum or something similar. I could also submit a pull request if this is a use case that benefits more people than just me.
I've not really worked with macros so far, but could probably make it work
Proposed Solutions
Example struct with "IdenGen" derive:
Generated Iden:
The text was updated successfully, but these errors were encountered: