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

Auto Generated ActiveEnum String Values And Model Column Names #2170

Merged
merged 9 commits into from
May 28, 2024

Conversation

anshap1719
Copy link
Contributor

@anshap1719 anshap1719 commented Mar 22, 2024

PR Info

New Features

  • Add support for column_name_case attribute in DeriveEntityModel for automatically generating column names for all fields based on case style provided.
  • Add support for column_name_case attribute in fields within a model that derives DeriveEntityModel for automatically generating column name based on case style provided.
  • Add support for rename_all attribute in DeriveActiveEnum for automatically generating string values for all variants of the enum based on case style provided.
  • Add support for rename attribute for variants of an ActiveEnum that derives DeriveActiveEnum for automatically generating string value for it based on case style provided.
  • Finalise names of newly added attributes.
  • Finalise allowed cases for column names
  • Finalise newly added error messages
  • Add documentation for new attributes

Dependents

@anshap1719
Copy link
Contributor Author

@tyt2y3 @billy1624 Can I ask for your opinions for these:

  • Finalise names of newly added attributes.
  • Finalise allowed cases for column names
  • Finalise newly added error messages

@anshap1719 anshap1719 force-pushed the auto-generated-active-enum-strings branch from 208c70c to f23ebac Compare March 22, 2024 19:33
@anshap1719
Copy link
Contributor Author

Hi @tyt2y3 @billy1624, sorry to ping you about this! Did you get a chance to look at it yet?

@tyt2y3 tyt2y3 requested a review from billy1624 April 24, 2024 17:20
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 @anshap1719, thanks for the PR! I think this is a good alternative to the existing renaming of entity columns and active enum variants!

@anshap1719 anshap1719 force-pushed the auto-generated-active-enum-strings branch from f23ebac to 35bca74 Compare April 25, 2024 16:04
@anshap1719
Copy link
Contributor Author

@billy1624 This is ready for your review in my opinion.

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.

Thanks!! @anshap1719

@billy1624 billy1624 requested a review from tyt2y3 May 2, 2024 07:13
@anshap1719
Copy link
Contributor Author

Thanks @billy1624

@anshap1719
Copy link
Contributor Author

@tyt2y3 Please review.

Copy link
Member

@tyt2y3 tyt2y3 left a comment

Choose a reason for hiding this comment

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

Nice work! Thank you

@tyt2y3 tyt2y3 merged commit 33230ab into SeaQL:master May 28, 2024
32 checks passed
@anshap1719
Copy link
Contributor Author

@tyt2y3 @billy1624 Thanks for all your help as well.

Copy link

🎉 Released In 1.0.0-rc.5 🎉

Thank you everyone for the contribution!
This feature is now available in the latest release. Now is a good time to upgrade!
Your participation is what makes us unique; your adoption is what drives us forward.
You can support SeaQL 🌊 by starring our repos, sharing our libraries and becoming a sponsor ⭐.

@IgnisDa
Copy link
Contributor

IgnisDa commented May 30, 2024

@anshap1719 Just wanted to inform you that this no longer works:

#[derive(EnumIter, DeriveActiveEnum)]
#[sea_orm(
    rs_type = "String",
    db_type = "String(Some(1))",
    rename_all = "camelCase"
)]
pub enum Category {
    BigTask,
    SmallWork,
}

String(None) does not work as well.

image

Using sea-orm 1.0.0-rc.5.

EDIT: Nvm found the correct way:

#[derive(EnumIter, DeriveActiveEnum)]
#[sea_orm(rs_type = "String", db_type = "String(StringLen::None)", rename_all = "camelCase")]
pub enum TestEnum {
    DefaultVariant, // defaultVariant
    #[sea_orm(rename = "kebab-case")]
    VariantKebabCase, // variant-kebab-case
    #[sea_orm(rename = "snake_case")]
    VariantSnakeCase, // variant_snake_case
    #[sea_orm(string_value = "CuStOmStRiNgVaLuE")]
    CustomStringValue, // CuStOmStRiNgVaLuE
}

Copy link

github-actions bot commented Aug 4, 2024

🎉 Released In 1.0.0 🎉

Thank you everyone for the contribution!
This feature is now available in the latest release. Now is a good time to upgrade!
Your participation is what makes us unique; your adoption is what drives us forward.
You can support SeaQL 🌊 by starring our repos, sharing our libraries and becoming a sponsor ⭐.

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.

Allow Defaulting string_value For ActiveEnum Based On Renaming Rules On Variants
4 participants