Remove panic

This commit is contained in:
Marco Napetti 2021-09-06 12:21:21 +02:00
parent 0eb6902d1b
commit cc2f491a1e

View File

@ -1,7 +1,7 @@
use proc_macro2::{Ident, Span, TokenStream}; use proc_macro2::{Ident, Span, TokenStream};
use quote::quote; use quote::quote;
use syn::{Attribute, Data, Fields, Lit, Meta, punctuated::Punctuated, token::Comma}; use syn::{Attribute, Data, Fields, Lit, Meta, parse::Error, punctuated::Punctuated, spanned::Spanned, token::Comma};
use convert_case::{Case, Casing}; use convert_case::{Case, Casing};
@ -103,7 +103,10 @@ impl sea_orm::prelude::EntityName for Entity {
} }
} }
}); });
let field_type = sql_type.unwrap_or_else(|| {
let field_type = match sql_type {
Some(t) => t,
None => {
let field_type = &field.ty; let field_type = &field.ty;
let temp = quote! { #field_type } let temp = quote! { #field_type }
.to_string()//E.g.: "Option < String >" .to_string()//E.g.: "Option < String >"
@ -130,9 +133,10 @@ impl sea_orm::prelude::EntityName for Entity {
"NaiveDateTime" => quote! { DateTime }, "NaiveDateTime" => quote! { DateTime },
"Uuid" => quote! { Uuid }, "Uuid" => quote! { Uuid },
"Decimal" => quote! { BigInteger }, "Decimal" => quote! { BigInteger },
_ => panic!("unrecognized type {}", temp), _ => return Err(Error::new(field.span(), format!("unrecognized type {}", temp))),
} }
}); }
};
let mut match_row = quote! { Self::#field_name => sea_orm::prelude::ColumnType::#field_type.def() }; let mut match_row = quote! { Self::#field_name => sea_orm::prelude::ColumnType::#field_type.def() };
if nullable { if nullable {