sea-orm icon indicating copy to clipboard operation
sea-orm copied to clipboard

Auto Generated ActiveEnum String Values And Model Column Names

Open anshap1719 opened this issue 1 year ago • 4 comments
trafficstars

PR Info

  • Closes #2160, #2125

New Features

  • [x] Add support for column_name_case attribute in DeriveEntityModel for automatically generating column names for all fields based on case style provided.
  • [x] 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.
  • [x] Add support for rename_all attribute in DeriveActiveEnum for automatically generating string values for all variants of the enum based on case style provided.
  • [x] 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.
  • [x] Finalise names of newly added attributes.
  • [x] Finalise allowed cases for column names
  • [x] Finalise newly added error messages
  • [x] Add documentation for new attributes

Dependents

  • https://github.com/SeaQL/seaql.github.io/pull/121

anshap1719 avatar Mar 22 '24 19:03 anshap1719

@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 avatar Mar 22 '24 19:03 anshap1719

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

anshap1719 avatar Apr 24 '24 04:04 anshap1719

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

anshap1719 avatar Apr 28 '24 11:04 anshap1719

Thanks @billy1624

anshap1719 avatar May 02 '24 07:05 anshap1719

@tyt2y3 Please review.

anshap1719 avatar May 22 '24 02:05 anshap1719

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

anshap1719 avatar May 29 '24 05:05 anshap1719

:tada: Released In 1.0.0-rc.5 :tada:

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 ⭐.

github-actions[bot] avatar May 29 '24 15:05 github-actions[bot]

@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
}

IgnisDa avatar May 30 '24 01:05 IgnisDa

:tada: Released In 1.0.0 :tada:

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 ⭐.

github-actions[bot] avatar Aug 04 '24 12:08 github-actions[bot]