From d7472320a00fa0bfd6b9be904e0730461f093f61 Mon Sep 17 00:00:00 2001 From: 53hornet Date: Sat, 1 Jan 2022 12:27:41 -0500 Subject: chore: pre-ripping-apart --- src/repo/mod.rs | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'src/repo') 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, TwinHError> { let cars = REPO_INSTANCE .open_tree(CARS_TREE)? - .into_iter() - .values() - .collect::, _>>()? .iter() - .map(|c| deserialize::(&c)) + .collect::, _>>()? + .into_iter() + .map(|e| crate::models::Entity::new(e)) + .map(|e| e.map(|e| e.model)) .collect::, _>>()?; + // let cars = REPO_INSTANCE + // .open_tree(CARS_TREE)? + // .into_iter() + // .values() + // .collect::, _>>()? + // .iter() + // .map(|c| deserialize::(&c)) + // .collect::, _>>()?; Ok(cars) } @@ -51,7 +59,7 @@ pub fn insert_part(part: Part) -> Result { #[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(), }; -- cgit v1.2.3