Added the database datatype.
This commit is contained in:
parent
da26693242
commit
bb23397eb0
@ -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<DataType, MTTError> {
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user