Skip to content

Conversation

@Diwakar-Gupta
Copy link
Contributor

@Diwakar-Gupta Diwakar-Gupta commented Jan 21, 2023

Still Working need feedback

PR Info

Fixes
Problem discussed at #394 (comment).

Related PR

#1560

Tasks

  • Replace manually parsing with darling
  • Write test for parser

File Changed

  1. sea-orm-macros/Cargo.toml added darling dependency
  2. sea-orm-macros/src/derives/model.rs modified parser and added test

@Diwakar-Gupta Diwakar-Gupta force-pushed the macro-parsing-with-darling branch from 0488ff3 to 9e59ebc Compare January 21, 2023 06:27
Copy link
Member

@billy1624 billy1624 left a comment

Choose a reason for hiding this comment

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

Hey @Diwakar-Gupta, thanks for the work!!

  1. the test needs to be done in a different way

I think the test is on the right track! :)

  1. we need to change structure struct DeriveModel

Yes, would be better if we replace DeriveModel with DeriveModelDarling. As DeriveModelDarling already have all the info of DeriveModel.

Btw... a small nitpick. Should we name the derive data struct without the Daring prefix? For example, naming DeriveModelDarling as DeriveModel.

  1. Code generation need's to be changed

I'm not sure what you mean here. Could you please clarify?

  1. if this is going in right direction or not.

Good POC! Was in the right direction!
Appreciated the help :)

@Diwakar-Gupta
Copy link
Contributor Author

Diwakar-Gupta commented Jan 26, 2023

Thanks for the feedback.

I will look after replacing DeriveModel with DeriveModelDarling. This will lead to changes in impl_from_query_result impl_model_trait as they both depend on struct DeriveModel.

@tyt2y3
Copy link
Member

tyt2y3 commented Jan 26, 2023

Wow, interesting. I have never used darling. Seems like it can make the code much cleaner!

@billy1624
Copy link
Member

Yep, wanna get rid of the parsing mess ASAP loll

@Diwakar-Gupta Diwakar-Gupta force-pushed the macro-parsing-with-darling branch from 4045cf6 to ddacf80 Compare January 26, 2023 11:40
@billy1624
Copy link
Member

Hey @Diwakar-Gupta, I think you leave a comment here yesterday night but it's now gone. Anything I could help?

#[darling(default)]
enum_name: Option<String>,
#[darling(skip)]
column_ident: Option<Ident>,
Copy link
Contributor Author

@Diwakar-Gupta Diwakar-Gupta Jan 27, 2023

Choose a reason for hiding this comment

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

darling cant parse column_ident because it has out own logic so made it Option and then calculated it in constructor. Not sure if having a function get_column_ident will be better.
Having function will remove most of the calculation code in constructor but then we wont be able to use column_ident variable and have to call function( it has to be called twice ).

@Diwakar-Gupta
Copy link
Contributor Author

Diwakar-Gupta commented Jan 27, 2023

@billy1624
The comment was a report of changes done; Then I did some more changes and it became irrelevant.
Here is the latest summary.

All this are also commented in code.

  1. Previously DeriveModel had processed data, removing it has introduced some extra processing in impl_from_query_result and impl_model_trait functions. But it is manageable at least in my opinion.

  2. struct is only supported this is ensured by darling now, and default darling error message is shown to user for now. cant give custom error message unless darling makes some necessary module public.

@Diwakar-Gupta Diwakar-Gupta force-pushed the macro-parsing-with-darling branch from 650f6bf to c6757a0 Compare January 30, 2023 07:35
@Diwakar-Gupta Diwakar-Gupta force-pushed the macro-parsing-with-darling branch from ccee6f1 to 5000416 Compare February 15, 2023 08:16
This was referenced Mar 21, 2023
Copy link
Member

@billy1624 billy1624 left a comment

Choose a reason for hiding this comment

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

Hey @Diwakar-Gupta, I saw your implementation then I decided to try it before leaving comments. My experiment result: #1560

Feel free to copy the useful bits to your PR. Hopefully we can combine the "good" into single PR.

@Diwakar-Gupta
Copy link
Contributor Author

Thanks @billy1624 I will study the reference you have given.

@Diwakar-Gupta Diwakar-Gupta force-pushed the macro-parsing-with-darling branch from 177ad17 to 1118af2 Compare April 16, 2023 16:14
@Diwakar-Gupta
Copy link
Contributor Author

hey @billy1624 i have used your pr #1560 and fixed the merge conflict.

@billy1624 billy1624 added this to the 0.12.x milestone Jun 20, 2023
@billy1624 billy1624 removed this from the 0.12.x milestone Jun 30, 2023
@billy1624 billy1624 linked an issue Jun 30, 2023 that may be closed by this pull request
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 this pull request may close these issues.

Throw compile errors when unexpected proc_macros attributes are provided Replacing bae with darling

3 participants