Added pull record information.
This commit is contained in:
		@@ -9,7 +9,7 @@ pub enum CacheType {
 | 
			
		||||
 | 
			
		||||
#[derive(Clone)]
 | 
			
		||||
pub struct Record {
 | 
			
		||||
    data: HashMap<String, String>
 | 
			
		||||
    data: HashMap<String, String>,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl Record {
 | 
			
		||||
@@ -25,7 +25,14 @@ impl Record {
 | 
			
		||||
            None => {
 | 
			
		||||
                self.data.insert(col.to_string(), data.to_string());
 | 
			
		||||
                Ok(())
 | 
			
		||||
            },
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fn get_field(&self, col: &str) -> Result<String, DBError> {
 | 
			
		||||
        match self.data.get(col) {
 | 
			
		||||
            Some(item) => Ok(item.to_string()),
 | 
			
		||||
            None => Err(DBError::new("missing field")),
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -119,8 +126,11 @@ mod record {
 | 
			
		||||
 | 
			
		||||
    #[test]
 | 
			
		||||
    fn store() {
 | 
			
		||||
        let data = "data";
 | 
			
		||||
        let mut rec = Record::new();
 | 
			
		||||
        rec.add_field("column", "data").unwrap();
 | 
			
		||||
        rec.add_field("column", data).unwrap();
 | 
			
		||||
        let output = rec.get_field("column").unwrap();
 | 
			
		||||
        assert_eq!(output, data);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    #[test]
 | 
			
		||||
@@ -131,7 +141,16 @@ mod record {
 | 
			
		||||
            Ok(_) => assert!(false, "Should have raised an error."),
 | 
			
		||||
            Err(err) => {
 | 
			
		||||
                assert_eq!(err.to_string(), "duplicate field");
 | 
			
		||||
            },
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    #[test]
 | 
			
		||||
    fn missing_field() {
 | 
			
		||||
        let rec = Record::new();
 | 
			
		||||
        match rec.get_field("nothing") {
 | 
			
		||||
            Ok(_) => assert!(false, "Should have errored."),
 | 
			
		||||
            Err(err) => assert_eq!(err.to_string(), "missing field"),
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user