Pārlūkot izejas kodu

Add loading of integers for models.

Kestrel 2 gadi atpakaļ
vecāks
revīzija
9a88b9148e
3 mainītis faili ar 31 papildinājumiem un 5 dzēšanām
  1. 0 2
      microrm-macros/src/lib.rs
  2. 0 2
      microrm/src/model/create.rs
  3. 31 1
      microrm/src/model/load.rs

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

@@ -38,8 +38,6 @@ pub fn derive_model(tokens: TokenStream) -> TokenStream {
                 value_references.push(quote!{ &self. #field_name });
             }
 
-            println!("field_names: {}", quote!{ #field_names });
-
             let field_count = fields.named.len();
 
             let ret = quote!{

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

@@ -53,8 +53,6 @@ impl<'de> serde::de::SeqAccess<'de> for CreateDeserializer<'de> {
     }
 }
 
-// trait SQLFor: crate::model::Entity
-
 pub fn sql_for<'de, T: crate::model::EntityColumn + crate::model::Entity + serde::de::Deserialize<'de>>() -> (String,String) {
     let mut cd = CreateDeserializer { table_name: None, column_names: None, column_types: Vec::new(), _de: std::marker::PhantomData{} };
 

+ 31 - 1
microrm/src/model/load.rs

@@ -26,6 +26,36 @@ impl<'de, 'a> serde::de::Deserializer<'de> for &'a mut RowDeserializer<'de> {
         todo!()
     }
 
+    fn deserialize_bool<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Self::Error> {
+        let res = v.visit_bool(self.row.get(self.col_index)?);
+        self.col_index += 1;
+        res
+    }
+
+    fn deserialize_i8<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Self::Error> {
+        let res = v.visit_i8(self.row.get(self.col_index)?);
+        self.col_index += 1;
+        res
+    }
+
+    fn deserialize_i16<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Self::Error> {
+        let res = v.visit_i16(self.row.get(self.col_index)?);
+        self.col_index += 1;
+        res
+    }
+
+    fn deserialize_i32<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Self::Error> {
+        let res = v.visit_i32(self.row.get(self.col_index)?);
+        self.col_index += 1;
+        res
+    }
+
+    fn deserialize_i64<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Self::Error> {
+        let res = v.visit_i64(self.row.get(self.col_index)?);
+        self.col_index += 1;
+        res
+    }
+
     fn deserialize_string<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Self::Error> {
         let res = v.visit_string(self.row.get(self.col_index)?);
         self.col_index += 1;
@@ -37,7 +67,7 @@ impl<'de, 'a> serde::de::Deserializer<'de> for &'a mut RowDeserializer<'de> {
     }
 
     serde::forward_to_deserialize_any! {
-        bool i8 i16 i32 i64 i128 u8 u16 u32 u64 u128 f32 f64 char str
+        i128 u8 u16 u32 u64 u128 f32 f64 char str
         bytes byte_buf option unit unit_struct newtype_struct seq tuple
         tuple_struct map enum identifier ignored_any
     }