Stubbed out database.
This commit is contained in:
		@@ -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
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										30
									
								
								src/morethantext/database.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								src/morethantext/database.rs
									
									
									
									
									
										Normal 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())
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -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::{
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user