Stubbed out database.

This commit is contained in:
Jeff Baskin 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::{ use async_std::{
fs::{read, remove_file, write}, fs::{read, remove_file, write},
path::{Path, PathBuf}, path::{Path, PathBuf},
@ -15,6 +15,7 @@ const ENTRY: &str = "EntryPoint";
#[derive(Clone)] #[derive(Clone)]
enum DataType { enum DataType {
DBMap(Store), DBMap(Store),
TableMap(Database),
} }
impl DataType { impl DataType {
@ -32,18 +33,21 @@ impl SessionData for DataType {
fn add(&mut self, key: &str, value: &str, data: &str) -> Result<Vec<String>, DBError> { fn add(&mut self, key: &str, value: &str, data: &str) -> Result<Vec<String>, DBError> {
match self { match self {
DataType::DBMap(dbs) => dbs.add(key, value, data), DataType::DBMap(dbs) => dbs.add(key, value, data),
DataType::TableMap(_) => todo!(),
} }
} }
fn eq(&self, key: &str, value: &str) -> Result<Vec<String>, DBError> { fn eq(&self, key: &str, value: &str) -> Result<Vec<String>, DBError> {
match self { match self {
DataType::DBMap(dbs) => dbs.eq(key, value), DataType::DBMap(dbs) => dbs.eq(key, value),
DataType::TableMap(_) => todo!(),
} }
} }
fn list(&self, keys: Vec<&str>) -> Result<Vec<String>, DBError> { fn list(&self, keys: Vec<&str>) -> Result<Vec<String>, DBError> {
match self { match self {
DataType::DBMap(dbs) => dbs.list(keys), 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.append(&mut "DBMap".as_bytes().to_vec());
output.push(0); output.push(0);
output.append(&mut store.to_bytes()); output.append(&mut store.to_bytes());
} },
DataType::TableMap(_) => todo!(),
} }
output output
} }

View File

@ -0,0 +1,30 @@
use super::{DBError, ErrorCode, FileData, SessionData, Store};
use std::slice;
#[derive(Clone)]
pub struct Database;
impl FileData<Self> for Database {
fn to_bytes(&self) -> Vec<u8> {
let output = Vec::new();
output
}
fn from_bytes(data: &mut slice::Iter<u8>) -> Result<Self, DBError> {
Ok(Self {})
}
}
impl SessionData for Database {
fn add(&mut self, key: &str, value: &str, data: &str) -> Result<Vec<String>, DBError> {
Ok(Vec::new())
}
fn eq(&self, key: &str, value: &str) -> Result<Vec<String>, DBError> {
Ok(Vec::new())
}
fn list(&self, keys: Vec<&str>) -> Result<Vec<String>, DBError> {
Ok(Vec::new())
}
}

View File

@ -1,4 +1,5 @@
mod cache; mod cache;
mod database;
pub mod error; pub mod error;
mod store; mod store;
@ -8,6 +9,7 @@ use async_std::{
sync::{Arc, Mutex}, sync::{Arc, Mutex},
task::{sleep, spawn}, task::{sleep, spawn},
}; };
use database::Database;
use error::{DBError, ErrorCode}; use error::{DBError, ErrorCode};
use rand::{distributions::Alphanumeric, thread_rng, Rng}; use rand::{distributions::Alphanumeric, thread_rng, Rng};
use std::{ use std::{