From bb23397eb025d1fe562cdcdd8bce14460caf8d67 Mon Sep 17 00:00:00 2001 From: Jeff Baskin Date: Mon, 10 Apr 2023 07:52:53 -0400 Subject: [PATCH] Added the database datatype. --- src/morethantext/mod.rs | 52 ++++++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 19 deletions(-) diff --git a/src/morethantext/mod.rs b/src/morethantext/mod.rs index 7b498c5..afef5c0 100644 --- a/src/morethantext/mod.rs +++ b/src/morethantext/mod.rs @@ -136,18 +136,37 @@ mod stores { } } +#[derive(Clone, Debug)] +struct Database; + +#[cfg(test)] +mod databases { + use super::*; + + #[test] + fn create() { + Database::new(); + } +} + +impl Database { + fn new() -> Self { + Self {} + } +} + #[derive(Clone, Debug)] enum DataType { DBMap(Store), + TableMap(Database), } impl DataType { - fn new(dtype: &str) -> Result { + fn new(dtype: &str) -> DataType { match dtype { - "store" => Ok(Self::DBMap(Store::new())), - _ => Err(MTTError::from_code(ErrorCode::IncorrectDataType( - dtype.to_string(), - ))), + "store" => Self::DBMap(Store::new()), + "database" => Self::TableMap(Database::new()), + _ => unreachable!(), } } } @@ -157,24 +176,19 @@ mod datatypes { use super::*; #[test] - fn error_on_bad_datatype() { - let items = ["sdgthsth", "jfjty"]; - for item in items { - match DataType::new(item) { - Ok(_) => assert!(false, "bad data types should return an error"), - Err(err) => match err.code { - ErrorCode::IncorrectDataType(dtype) => assert_eq!(dtype, item), - _ => assert!(false, "{:?} is not incorrect data type", err.code), - }, - } + fn create_store() { + let dtype = DataType::new("store"); + match dtype { + DataType::DBMap(_) => (), + _ => assert!(false, "{:?} is not incorrect data type", dtype), } } #[test] - fn create_store() { - let dtype = DataType::new("store").unwrap(); + fn create_database() { + let dtype = DataType::new("database"); match dtype { - DataType::DBMap(_) => (), + DataType::TableMap(_) => (), _ => assert!(false, "{:?} is not incorrect data type", dtype), } } @@ -241,7 +255,7 @@ impl Cache { for id in data.ids { if id == ENTRY { let mut holder = HashMap::new(); - holder.insert(ENTRY.to_string(), DataType::new("store").unwrap()); + holder.insert(ENTRY.to_string(), DataType::new("store")); data.reply.send(FromCache::Data(holder)).await.unwrap(); } else { data.reply