SeaQL / sea-orm

🐚 An async & dynamic ORM for Rust
https://www.sea-ql.org/SeaORM/
Apache License 2.0
7.03k stars 493 forks source link

Allow Defaulting `string_value` For ActiveEnum Based On Renaming Rules On Variants #2160

Closed anshap1719 closed 4 months ago

anshap1719 commented 6 months ago

Discussed in https://github.com/SeaQL/sea-orm/discussions/2125

Originally posted by **wyatt-herkamp** March 1, 2024 Take the following enum. I think we should automatically use the Variant name if the string_value is not provided. ```rust #[derive(DeriveActiveEnum)] #[sea_orm(rs_type = "String", db_type = "Enum", enum_name = "Interval")] pub enum Intervals { #[sea_orm(string_value = "Weekly")] Weekly, #[sea_orm(string_value = "BIWeekly")] BIWeekly, #[sea_orm(string_value = "Monthly")] Monthly, #[sea_orm(string_value = "Quarterly")] Quarterly, #[sea_orm(string_value = "Yearly")] Yearly, } ``` This would allow people to do ```rust #[derive(DeriveActiveEnum)] #[sea_orm(rs_type = "String", db_type = "Enum", enum_name = "Interval")] pub enum Intervals { Weekly, BIWeekly, Monthly, Quarterly, Yearly, } ``` And get the same result. I would be happy to make a PR if the developers of the project is Ok with this feature.
anshap1719 commented 6 months ago

@tyt2y3 While I was working on this, it made sense to also have this for model structs, so i decided to add that in (will be pushing later today). Let me know if there are any arguments against that.