Adding data retrival.
All checks were successful
MoreThanText/morethantext/pipeline/head This commit looks good
All checks were successful
MoreThanText/morethantext/pipeline/head This commit looks good
This commit is contained in:
parent
731cd01613
commit
aed94d7eac
120
src/data/cache.rs
Normal file
120
src/data/cache.rs
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
pub mod database;
|
||||||
|
pub mod global;
|
||||||
|
pub mod id;
|
||||||
|
mod record;
|
||||||
|
pub mod table;
|
||||||
|
|
||||||
|
/*
|
||||||
|
use std::collections::BTreeMap;
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
|
#[derive(PartialEq, Eq, Hash, PartialOrd, Ord, Clone, Debug)]
|
||||||
|
struct IDPath {
|
||||||
|
path: Vec<Uuid>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl IDPath {
|
||||||
|
fn new() -> Self {
|
||||||
|
let mut path = Vec::new();
|
||||||
|
path.push(Uuid::nil());
|
||||||
|
Self { path: path }
|
||||||
|
}
|
||||||
|
|
||||||
|
fn next() -> Uuid {
|
||||||
|
Uuid::new_v4()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn extend(&self, addition: Uuid) -> Self {
|
||||||
|
let mut result = self.clone();
|
||||||
|
result.path.pop();
|
||||||
|
result.path.push(addition);
|
||||||
|
result.path.push(Uuid::nil());
|
||||||
|
result
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod ids {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn create_idpath() {
|
||||||
|
let expected = [Uuid::nil()];
|
||||||
|
let id = IDPath::new();
|
||||||
|
assert_eq!(id.path, expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn next_is_random() {
|
||||||
|
let mut ids: Vec<Uuid> = Vec::new();
|
||||||
|
for _ in 0..10 {
|
||||||
|
let id = IDPath::next();
|
||||||
|
assert!(!ids.contains(&id), "{} is a duplicate", id);
|
||||||
|
ids.push(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn extend_idpath() {
|
||||||
|
let mut path: Vec<Uuid> = Vec::new();
|
||||||
|
path.push(Uuid::nil());
|
||||||
|
let mut id = IDPath::new();
|
||||||
|
for count in 1..5 {
|
||||||
|
assert_eq!(id.path.len(), count);
|
||||||
|
let extended = IDPath::next();
|
||||||
|
id = id.extend(extended.clone());
|
||||||
|
path.pop();
|
||||||
|
path.push(extended);
|
||||||
|
path.push(Uuid::nil());
|
||||||
|
assert_eq!(id.path, path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
struct Cache {
|
||||||
|
data: BTreeMap<String, IDPath>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Cache {
|
||||||
|
fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
data: BTreeMap::new(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn add_database<S>(&mut self, name: S)
|
||||||
|
where
|
||||||
|
S: Into<String>,
|
||||||
|
{
|
||||||
|
self.data.insert(name.into(), IDPath::new());
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_databases(&self) -> Vec<String> {
|
||||||
|
self.data.keys().cloned().collect()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod caches {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn create_cache() {
|
||||||
|
let cache = Cache::new();
|
||||||
|
let dbs = cache.get_databases();
|
||||||
|
assert!(dbs.is_empty());
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
#[test]
|
||||||
|
fn add_databases() {
|
||||||
|
let mut cache = Cache::new();
|
||||||
|
cache.add_database("zed");
|
||||||
|
cache.add_database("alpha".to_string());
|
||||||
|
cache.add_database("beta");
|
||||||
|
cache.add_database("gamma".to_string());
|
||||||
|
assert_eq!(cache.get_databases(), ["alpha", "beta", "gamma", "zed"]);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
@ -4,7 +4,12 @@ pub mod id;
|
|||||||
mod record;
|
mod record;
|
||||||
pub mod table;
|
pub mod table;
|
||||||
|
|
||||||
use std::collections::BTreeMap;
|
use std::{
|
||||||
|
collections::BTreeMap,
|
||||||
|
sync::mpsc::{Receiver, Sender, channel},
|
||||||
|
thread::spawn,
|
||||||
|
};
|
||||||
|
use super::Message;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, Hash, PartialOrd, Ord, Clone, Debug)]
|
#[derive(PartialEq, Eq, Hash, PartialOrd, Ord, Clone, Debug)]
|
||||||
@ -33,7 +38,7 @@ impl IDPath {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod ids {
|
mod idpaths {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -70,47 +75,42 @@ mod ids {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Cache {
|
struct Data {
|
||||||
data: BTreeMap<String, IDPath>,
|
router_tx: Sender<Message>,
|
||||||
|
data_rx: Receiver<Message>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Cache {
|
impl Data {
|
||||||
fn new() -> Self {
|
fn new(router_tx: Sender<Message>, data_rx: Receiver<Message>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
data: BTreeMap::new(),
|
router_tx: router_tx,
|
||||||
|
data_rx: data_rx,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_database<S>(&mut self, name: S)
|
pub fn start(router_tx: Sender<Message>) -> Sender<Message> {
|
||||||
where
|
let (data_tx, data_rx) = channel();
|
||||||
S: Into<String>,
|
spawn(move || {
|
||||||
{
|
let mut req = Data::new(router_tx, data_rx);
|
||||||
self.data.insert(name.into(), IDPath::new());
|
req.listen();
|
||||||
|
});
|
||||||
|
data_tx
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_databases(&self) -> Vec<String> {
|
fn listen(&mut self) {
|
||||||
self.data.keys().cloned().collect()
|
loop {
|
||||||
|
let msg = self.data_rx.recv().unwrap();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod caches {
|
mod requests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn create_cache() {
|
fn add_database() {
|
||||||
let cache = Cache::new();
|
let (tx, rx) = channel();
|
||||||
let dbs = cache.get_databases();
|
let data_tx = Data::start(tx);
|
||||||
assert!(dbs.is_empty());
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn add_databases() {
|
|
||||||
let mut cache = Cache::new();
|
|
||||||
cache.add_database("zed");
|
|
||||||
cache.add_database("alpha".to_string());
|
|
||||||
cache.add_database("beta");
|
|
||||||
cache.add_database("gamma".to_string());
|
|
||||||
assert_eq!(cache.get_databases(), ["alpha", "beta", "gamma", "zed"]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
48
src/lib.rs
48
src/lib.rs
@ -11,6 +11,54 @@ use router::Router;
|
|||||||
use session::{Session, SessionData, SessionMsg};
|
use session::{Session, SessionData, SessionMsg};
|
||||||
use std::sync::mpsc::{channel, Sender};
|
use std::sync::mpsc::{channel, Sender};
|
||||||
|
|
||||||
|
struct Request;
|
||||||
|
|
||||||
|
struct Record;
|
||||||
|
|
||||||
|
struct Response {
|
||||||
|
headers: Vec<String>,
|
||||||
|
records: Vec<Record>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Response {
|
||||||
|
fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
headers: Vec::new(),
|
||||||
|
records: Vec::new(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn count(&self) -> usize {
|
||||||
|
0
|
||||||
|
}
|
||||||
|
|
||||||
|
fn add_header<S>(&mut self, name: S) where S: Into<String> {
|
||||||
|
self.headers.push(name.into());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod responses {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn create_response() {
|
||||||
|
let res = Response::new();
|
||||||
|
assert!(res.headers.is_empty());
|
||||||
|
assert!(res.records.is_empty());
|
||||||
|
assert_eq!(res.count(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn addA_header() {
|
||||||
|
let mut res = Response::new();
|
||||||
|
res.add_header("one");
|
||||||
|
assert_eq!(res.headers, ["one"]);
|
||||||
|
res.add_header("two".to_string());
|
||||||
|
assert_eq!(res.headers, ["one", "two"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Support functions for Messages.
|
/// Support functions for Messages.
|
||||||
pub trait Msg {
|
pub trait Msg {
|
||||||
fn to_msgdata(&self) -> MsgData;
|
fn to_msgdata(&self) -> MsgData;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user