Stubbed out database.

This commit is contained in:
2023-03-16 22:32:10 -04:00
parent e125d79a6c
commit 418ba26da9
3 changed files with 39 additions and 2 deletions

View File

@ -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<Vec<String>, DBError> {
match self {
DataType::DBMap(dbs) => dbs.add(key, value, data),
DataType::TableMap(_) => todo!(),
}
}
fn eq(&self, key: &str, value: &str) -> Result<Vec<String>, DBError> {
match self {
DataType::DBMap(dbs) => dbs.eq(key, value),
DataType::TableMap(_) => todo!(),
}
}
fn list(&self, keys: Vec<&str>) -> Result<Vec<String>, DBError> {
match self {
DataType::DBMap(dbs) => dbs.list(keys),
DataType::TableMap(_) => todo!(),
}
}
}
@ -56,7 +60,8 @@ impl FileData<Self> for DataType {
output.append(&mut "DBMap".as_bytes().to_vec());
output.push(0);
output.append(&mut store.to_bytes());
}
},
DataType::TableMap(_) => todo!(),
}
output
}