diff options
author | 53hornet <atc@53hor.net> | 2022-01-01 12:27:41 -0500 |
---|---|---|
committer | 53hornet <atc@53hor.net> | 2022-01-01 12:27:41 -0500 |
commit | d7472320a00fa0bfd6b9be904e0730461f093f61 (patch) | |
tree | eadbbfd9a3b82eaafff30d0114fa7c0c7ca66e7d /src/repo | |
parent | 5d2c25bf3b196321ded7b7c7ac9ab9a2021fe9c3 (diff) | |
download | twinh-d7472320a00fa0bfd6b9be904e0730461f093f61.tar.xz twinh-d7472320a00fa0bfd6b9be904e0730461f093f61.zip |
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(), }; |