Эх сурвалжийг харах

Improve get_one_by_multi ergonomics.

Kestrel 2 жил өмнө
parent
commit
8457c8c01c

+ 4 - 1
microrm-macros/src/entity.rs

@@ -59,7 +59,10 @@ fn derive_columns<'a, I: Iterator<Item=&'a syn::Field>>(input: &DeriveInput, mic
                 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_consts.push(quote! {
+            #[allow(non_upper_case_globals)]
+            pub const #converted_case : #columns_name::#converted_case = #columns_name::#converted_case();
+        });
 
         column_array.push(quote! { & #columns_name::#converted_case() });
     }

+ 6 - 6
microrm/src/query.rs

@@ -204,19 +204,19 @@ impl<'l> QueryInterface<'l> {
 
     /// Search for an entity by multiple properties
     pub fn get_one_by_multi<
-        C: EntityColumn,
+        T: Entity
     >(
         &self,
-        c: &[&dyn EntityColumn<Entity = C::Entity>],
+        c: &[&dyn EntityColumn<Entity = T>],
         val: &[&dyn crate::model::Modelable],
-    ) -> Option<WithID<C::Entity>> {
-        let table_name = <C::Entity as Entity>::table_name();
+    ) -> Option<WithID<T>> {
+        let table_name = T::table_name();
 
         assert_eq!(c.len(), val.len());
 
         self.cached_query_column(
             "get_one_by_multi",
-            std::any::TypeId::of::<C::Entity>(),
+            std::any::TypeId::of::<T>(),
             c,
             &|| {
                 let query = format!(
@@ -239,7 +239,7 @@ impl<'l> QueryInterface<'l> {
 
                 self.expect_one_result(stmt, &mut |stmt| {
                     let id: i64 = stmt.read(0).ok()?;
-                    Some(WithID::wrap(C::Entity::build_from(stmt).ok()?, id))
+                    Some(WithID::wrap(T::build_from(stmt).ok()?, id))
                 })
             },
         )