-
-
Notifications
You must be signed in to change notification settings - Fork 524
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
codegen ActiveEnum & create enum from ActiveEnum
- Loading branch information
Showing
9 changed files
with
173 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use heck::CamelCase; | ||
use proc_macro2::TokenStream; | ||
use quote::{format_ident, quote}; | ||
|
||
#[derive(Clone, Debug)] | ||
pub struct ActiveEnum { | ||
pub(crate) enum_name: String, | ||
pub(crate) values: Vec<String>, | ||
} | ||
|
||
impl ActiveEnum { | ||
pub fn impl_active_enum(&self) -> TokenStream { | ||
let enum_name = &self.enum_name; | ||
let enum_iden = format_ident!("{}", enum_name.to_camel_case()); | ||
let values = &self.values; | ||
let variants = self | ||
.values | ||
.iter() | ||
.map(|v| format_ident!("{}", v.to_camel_case())); | ||
quote! { | ||
#[derive(Debug, Clone, PartialEq, EnumIter, DeriveActiveEnum)] | ||
#[sea_orm(rs_type = "String", db_type = "Enum", enum_name = #enum_name)] | ||
pub enum #enum_iden { | ||
#( | ||
#[sea_orm(string_value = #values)] | ||
#variants, | ||
)* | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters