diff options
Diffstat (limited to 'src/repo')
-rw-r--r-- | src/repo/mod.rs | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/src/repo/mod.rs b/src/repo/mod.rs index 80b2814..4c55696 100644 --- a/src/repo/mod.rs +++ b/src/repo/mod.rs @@ -35,12 +35,20 @@ pub fn create_new_db() -> Result<(), TwinHError> { pub fn get_all_cars() -> Result<Vec<Car>, TwinHError> { let cars = REPO_INSTANCE .open_tree(CARS_TREE)? - .into_iter() - .values() - .collect::<Result<Vec<_>, _>>()? .iter() - .map(|c| deserialize::<Car>(&c)) + .collect::<Result<Vec<_>, _>>()? + .into_iter() + .map(|e| crate::models::Entity::new(e)) + .map(|e| e.map(|e| e.model)) .collect::<Result<Vec<_>, _>>()?; + // let cars = REPO_INSTANCE + // .open_tree(CARS_TREE)? + // .into_iter() + // .values() + // .collect::<Result<Vec<_>, _>>()? + // .iter() + // .map(|c| deserialize::<Car>(&c)) + // .collect::<Result<Vec<_>, _>>()?; Ok(cars) } @@ -51,7 +59,7 @@ pub fn insert_part(part: Part) -> Result<u64, TwinHError> { #[cfg(test)] mod tests { use super::*; - use crate::models::{Car, Part}; + use crate::models::{Car, Entity, Part}; use bincode::serialize; use std::error::Error; @@ -63,7 +71,6 @@ mod tests { .open()?; let car = Car { - key: 1, make: "Hudson".into(), model: "Hornet".into(), trim: "Sedan".into(), @@ -71,8 +78,10 @@ mod tests { year: 1953, }; + let entity = Entity(1, &car); + let tree = db.open_tree(CARS_TREE)?; - let key = car.key.to_be_bytes(); + let key = entity.0.to_be_bytes(); let val = serialize(&car)?; tree.insert(key, val)?; @@ -80,7 +89,7 @@ mod tests { key: 2, number: "ABC123".into(), name: "Rear Wheel Bearing".into(), - fits_cars: vec![car.key], + fits_cars: vec![entity.0], categories: Vec::new(), sources: Vec::new(), }; |