Jelajahi Sumber

Minor cleanups and rustfmt pass.

Kestrel 2 tahun lalu
induk
melakukan
bf9edf5e0c

+ 0 - 3
microrm-macros/src/lib.rs

@@ -108,9 +108,6 @@ pub fn derive_entity(tokens: TokenStream) -> TokenStream {
         value_references.push(quote! { &self. #field_name });
     }
 
-    let fk_array_ident = format_ident!("FOREIGN_KEYS_{}", struct_name);
-    let fk_array_len = foreign_keys.len();
-
     let field_count = fields.named.iter().count();
 
     quote!{

+ 1 - 1
microrm/src/lib.rs

@@ -212,7 +212,7 @@ mod test {
     #[microrm_internal]
     pub struct S2 {
         #[microrm_foreign]
-        parent_id: S1ID
+        parent_id: S1ID,
     }
 
     #[test]

+ 0 - 6
microrm/src/model.rs

@@ -83,12 +83,6 @@ pub trait EntityForeignKey<T: EntityColumns> {
     fn foreign_column_name(&self) -> &'static str;
 }
 
-impl<E: Entity<Column = T>, T: EntityColumns<Entity = E>> EntityForeignKey<T> for (T, &'static str, &'static str) {
-    fn local_column(&self) -> &T { &self.0 }
-    fn foreign_table_name(&self) -> &'static str { self.1 }
-    fn foreign_column_name(&self) -> &'static str { self.2 }
-}
-
 /// How we describe an entire schema
 #[derive(Debug)]
 pub struct SchemaModel {

+ 2 - 1
microrm/src/model/create.rs

@@ -236,7 +236,8 @@ mod test {
             super::sql_for::<UnitNewtype>(),
             (
                 r#"DROP TABLE IF EXISTS "unit_newtype""#.to_owned(),
-                r#"CREATE TABLE "unit_newtype" (id integer primary key, "newtype" integer)"#.to_owned()
+                r#"CREATE TABLE "unit_newtype" (id integer primary key, "newtype" integer)"#
+                    .to_owned()
             )
         );
     }

+ 2 - 5
microrm/src/query.rs

@@ -110,10 +110,7 @@ pub fn get_one_by_id<T: Entity>(db: &DB, id: <T as Entity>::ID) -> Option<WithID
     let table_name = <T as Entity>::table_name();
     let mut prepared = db
         .conn
-        .prepare(&format!(
-            "SELECT * FROM \"{}\" WHERE id = ?1",
-            table_name
-        ))
+        .prepare(&format!("SELECT * FROM \"{}\" WHERE id = ?1", table_name))
         .ok()?;
 
     let result = prepared.query_row([&id], |row| {
@@ -131,7 +128,7 @@ pub fn get_one_by_id<T: Entity>(db: &DB, id: <T as Entity>::ID) -> Option<WithID
 pub fn add<T: Entity + serde::Serialize>(db: &DB, m: &T) -> Option<<T as Entity>::ID> {
     let row = crate::model::store::serialize_as_row(m);
 
-    let placeholders = (0..(<T as Entity>::column_count()-1))
+    let placeholders = (0..(<T as Entity>::column_count() - 1))
         .map(|n| format!("?{}", n + 1))
         .collect::<Vec<_>>()
         .join(",");