Add indexed_fields method on Model
For postgres indexes we want to know the indexed field names upfront without an actual instance of Model Signed-off-by: Lee Smet <lee.smet@hotmail.com>
This commit is contained in:
		@@ -123,6 +123,11 @@ pub fn model(_attr: TokenStream, item: TokenStream) -> TokenStream {
 | 
			
		||||
        }
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    let indexed_field_names = indexed_fields
 | 
			
		||||
        .iter()
 | 
			
		||||
        .map(|f| f.0.to_string())
 | 
			
		||||
        .collect::<Vec<_>>();
 | 
			
		||||
 | 
			
		||||
    let model_impl = quote! {
 | 
			
		||||
        impl heromodels_core::Model for #struct_name {
 | 
			
		||||
            fn db_prefix() -> &'static str {
 | 
			
		||||
@@ -137,6 +142,12 @@ pub fn model(_attr: TokenStream, item: TokenStream) -> TokenStream {
 | 
			
		||||
                &mut self.base_data
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            fn indexed_fields() -> Vec<&'static str> {
 | 
			
		||||
                vec![
 | 
			
		||||
                    #(#indexed_field_names),*
 | 
			
		||||
                ]
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            #db_keys_impl
 | 
			
		||||
        }
 | 
			
		||||
    };
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user