|
@@ -37,21 +37,30 @@ fn derive_columns<'a, I: Iterator<Item=&'a syn::Field>>(input: &DeriveInput, mic
|
|
|
|
|
|
let ty = &name.ty;
|
|
|
|
|
|
+ let mut fk_table_name = quote! { None };
|
|
|
+ let mut fk_column_name = quote! { None };
|
|
|
+
|
|
|
+ if parse_fk(&name.attrs) {
|
|
|
+ fk_table_name = quote! { Some(<<#ty as #microrm_ref::entity::EntityID>::Entity as #microrm_ref::entity::Entity>::table_name()) };
|
|
|
+ fk_column_name = quote! { Some("id") };
|
|
|
+ }
|
|
|
+
|
|
|
index += 1;
|
|
|
column_types.push(quote! { pub struct #converted_case (); });
|
|
|
column_impls.push(quote! {
|
|
|
impl #microrm_ref::entity::EntityColumn for #columns_name::#converted_case {
|
|
|
- type Entity = super::#struct_name;
|
|
|
- // XXX: #ty here may be in parent context
|
|
|
+ type Entity = #struct_name;
|
|
|
fn sql_type(&self) -> &'static str { <#ty as #microrm_ref::model::Modelable>::column_type() }
|
|
|
fn index(&self) -> usize { #index }
|
|
|
fn name(&self) -> &'static str { #snake_case }
|
|
|
+
|
|
|
+ fn fk_table_name(&self) -> Option<&'static str> { #fk_table_name }
|
|
|
+ fn fk_column_name(&self) -> Option<&'static str> { #fk_column_name }
|
|
|
}
|
|
|
});
|
|
|
column_consts.push(quote! { const #converted_case : #columns_name::#converted_case = #columns_name::#converted_case(); });
|
|
|
|
|
|
column_array.push(quote! { & #columns_name::#converted_case() });
|
|
|
-
|
|
|
}
|
|
|
|
|
|
let columns_array_name = format_ident!(
|
|
@@ -70,6 +79,9 @@ fn derive_columns<'a, I: Iterator<Item=&'a syn::Field>>(input: &DeriveInput, mic
|
|
|
fn sql_type(&self) -> &'static str { "integer" }
|
|
|
fn index(&self) -> usize { 0 }
|
|
|
fn name(&self) -> &'static str { "id" }
|
|
|
+
|
|
|
+ fn fk_table_name(&self) -> Option<&'static str> { None }
|
|
|
+ fn fk_column_name(&self) -> Option<&'static str> { None }
|
|
|
}
|
|
|
#(#column_impls)*
|
|
|
|
|
@@ -136,9 +148,11 @@ pub(crate) fn derive(tokens: TokenStream) -> TokenStream {
|
|
|
|
|
|
let mut variants = Vec::new();
|
|
|
let mut value_references = Vec::new();
|
|
|
-
|
|
|
let mut build_clauses = Vec::new();
|
|
|
|
|
|
+ // let mut foreign_keys = Vec::new();
|
|
|
+ // let mut foreign_key_impls = Vec::new();
|
|
|
+
|
|
|
let mut index: usize = 0;
|
|
|
|
|
|
let column_output = derive_columns(&input, µrm_ref, fields.named.iter());
|
|
@@ -163,6 +177,7 @@ pub(crate) fn derive(tokens: TokenStream) -> TokenStream {
|
|
|
index += 1;
|
|
|
build_clauses.push(quote! { #field_name: <#ty as #microrm_ref::model::Modelable>::build_from(stmt, #index)?.0 });
|
|
|
|
|
|
+
|
|
|
/*
|
|
|
if parse_fk(&name.attrs) {
|
|
|
let fk_struct_name = format_ident!("{}{}ForeignKey", struct_name, converted_case);
|