diff --git a/src/morethantext/cache.rs b/src/morethantext/cache.rs index 38630c9..8878770 100644 --- a/src/morethantext/cache.rs +++ b/src/morethantext/cache.rs @@ -1,4 +1,4 @@ -use super::{DBError, ErrorCode, FileData, SessionData, Store}; +use super::{Database, DBError, ErrorCode, FileData, SessionData, Store}; use async_std::{ fs::{read, remove_file, write}, path::{Path, PathBuf}, @@ -15,6 +15,7 @@ const ENTRY: &str = "EntryPoint"; #[derive(Clone)] enum DataType { DBMap(Store), + TableMap(Database), } impl DataType { @@ -32,18 +33,21 @@ impl SessionData for DataType { fn add(&mut self, key: &str, value: &str, data: &str) -> Result, DBError> { match self { DataType::DBMap(dbs) => dbs.add(key, value, data), + DataType::TableMap(_) => todo!(), } } fn eq(&self, key: &str, value: &str) -> Result, DBError> { match self { DataType::DBMap(dbs) => dbs.eq(key, value), + DataType::TableMap(_) => todo!(), } } fn list(&self, keys: Vec<&str>) -> Result, DBError> { match self { DataType::DBMap(dbs) => dbs.list(keys), + DataType::TableMap(_) => todo!(), } } } @@ -56,7 +60,8 @@ impl FileData for DataType { output.append(&mut "DBMap".as_bytes().to_vec()); output.push(0); output.append(&mut store.to_bytes()); - } + }, + DataType::TableMap(_) => todo!(), } output } diff --git a/src/morethantext/database.rs b/src/morethantext/database.rs new file mode 100644 index 0000000..31e7b3d --- /dev/null +++ b/src/morethantext/database.rs @@ -0,0 +1,30 @@ +use super::{DBError, ErrorCode, FileData, SessionData, Store}; +use std::slice; + +#[derive(Clone)] +pub struct Database; + +impl FileData for Database { + fn to_bytes(&self) -> Vec { + let output = Vec::new(); + output + } + + fn from_bytes(data: &mut slice::Iter) -> Result { + Ok(Self {}) + } +} + +impl SessionData for Database { + fn add(&mut self, key: &str, value: &str, data: &str) -> Result, DBError> { + Ok(Vec::new()) + } + + fn eq(&self, key: &str, value: &str) -> Result, DBError> { + Ok(Vec::new()) + } + + fn list(&self, keys: Vec<&str>) -> Result, DBError> { + Ok(Vec::new()) + } +} diff --git a/src/morethantext/mod.rs b/src/morethantext/mod.rs index 2f8c807..036313a 100644 --- a/src/morethantext/mod.rs +++ b/src/morethantext/mod.rs @@ -1,4 +1,5 @@ mod cache; +mod database; pub mod error; mod store; @@ -8,6 +9,7 @@ use async_std::{ sync::{Arc, Mutex}, task::{sleep, spawn}, }; +use database::Database; use error::{DBError, ErrorCode}; use rand::{distributions::Alphanumeric, thread_rng, Rng}; use std::{