(input: syn::DeriveInput)
| 23 | |
| 24 | impl DeriveModel { |
| 25 | fn new(input: syn::DeriveInput) -> Result<Self, Error> { |
| 26 | let fields = match input.data { |
| 27 | syn::Data::Struct(syn::DataStruct { |
| 28 | fields: syn::Fields::Named(syn::FieldsNamed { named, .. }), |
| 29 | .. |
| 30 | }) => named, |
| 31 | _ => return Err(Error::InputNotStruct), |
| 32 | }; |
| 33 | |
| 34 | let sea_attr = derive_attr::SeaOrm::try_from_attributes(&input.attrs) |
| 35 | .map_err(Error::Syn)? |
| 36 | .unwrap_or_default(); |
| 37 | |
| 38 | let ident = input.ident; |
| 39 | let entity_ident = sea_attr.entity.unwrap_or_else(|| format_ident!("Entity")); |
| 40 | |
| 41 | let field_idents = fields |
| 42 | .iter() |
| 43 | .map(|field| field.ident.as_ref().unwrap().clone()) |
| 44 | .collect(); |
| 45 | |
| 46 | let column_idents = fields |
| 47 | .iter() |
| 48 | .map(|field| { |
| 49 | let ident = field.ident.as_ref().unwrap().to_string(); |
| 50 | let ident = trim_starting_raw_identifier(ident).to_upper_camel_case(); |
| 51 | let ident = escape_rust_keyword(ident); |
| 52 | let mut ident = format_ident!("{}", &ident); |
| 53 | field |
| 54 | .attrs |
| 55 | .iter() |
| 56 | .filter(|attr| attr.path().is_ident("sea_orm")) |
| 57 | .try_for_each(|attr| { |
| 58 | attr.parse_nested_meta(|meta| { |
| 59 | if meta.path.is_ident("enum_name") { |
| 60 | ident = syn::parse_str(&meta.value()?.parse::<LitStr>()?.value()) |
| 61 | .unwrap(); |
| 62 | } else { |
| 63 | // Reads the value expression to advance the parse stream. |
| 64 | // Some parameters, such as `primary_key`, do not have any value, |
| 65 | // so ignoring an error occurred here. |
| 66 | let _: Option<Expr> = meta.value().and_then(|v| v.parse()).ok(); |
| 67 | } |
| 68 | |
| 69 | Ok(()) |
| 70 | }) |
| 71 | .map_err(Error::Syn) |
| 72 | })?; |
| 73 | Ok(ident) |
| 74 | }) |
| 75 | .collect::<Result<_, _>>()?; |
| 76 | |
| 77 | let ignore_attrs = fields |
| 78 | .iter() |
| 79 | .map(|field| !field_not_ignored(field)) |
| 80 | .collect(); |
| 81 | |
| 82 | Ok(DeriveModel { |
nothing calls this directly
no test coverage detected