|
@@ -68,6 +68,7 @@ pub fn derive_entity(tokens: TokenStream) -> TokenStream {
|
|
|
|
|
|
let mut variants = Vec::new();
|
|
|
let mut field_names = Vec::new();
|
|
|
+ let mut field_numbers = Vec::new();
|
|
|
let mut value_references = Vec::new();
|
|
|
|
|
|
let mut foreign_keys = Vec::new();
|
|
@@ -83,6 +84,9 @@ pub fn derive_entity(tokens: TokenStream) -> TokenStream {
|
|
|
let field_name_str = format!("{}", field_name);
|
|
|
field_names.push(quote! { Self::Column::#converted_case => #field_name_str });
|
|
|
|
|
|
+ let nn = field_numbers.len() + 1;
|
|
|
+ field_numbers.push(quote! { #nn => Self::#converted_case, });
|
|
|
+
|
|
|
if parse_fk(&name.attrs) {
|
|
|
let fk_struct_name = format_ident!("{}{}ForeignKey", struct_name, converted_case);
|
|
|
let ty = &name.ty;
|
|
@@ -112,7 +116,7 @@ pub fn derive_entity(tokens: TokenStream) -> TokenStream {
|
|
|
|
|
|
quote!{
|
|
|
// Related types for #struct_name
|
|
|
- #[derive(Clone,Copy,PartialEq,#microrm_ref::re_export::num_enum::TryFromPrimitive)]
|
|
|
+ #[derive(Clone,Copy,PartialEq)]
|
|
|
#[allow(unused)]
|
|
|
#[repr(usize)]
|
|
|
pub enum #enum_name {
|
|
@@ -129,6 +133,18 @@ pub fn derive_entity(tokens: TokenStream) -> TokenStream {
|
|
|
type Entity = #struct_name;
|
|
|
}
|
|
|
|
|
|
+ impl std::convert::From<usize> for #enum_name {
|
|
|
+ fn from(i: usize) -> Self {
|
|
|
+ match i {
|
|
|
+ 0 => Self::ID,
|
|
|
+ #(#field_numbers)*
|
|
|
+ _ => {
|
|
|
+ panic!("Given invalid usize to convert to column")
|
|
|
+ },
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
impl #microrm_ref::model::EntityID for #id_name {
|
|
|
type Entity = #struct_name;
|
|
|
fn from_raw_id(raw: i64) -> Self { Self(raw) }
|