pub mod error;
mod util;
use std::result;
use util::*;
use crate::error::ConnectionError;
type Result<T> = result::Result<T, Box<std::error::Error>>;
pub struct Store {
connection: String
}
impl Store {
pub fn new(connection: &str) -> Result<Store> {
let result = handle("TEST", connection);
if let Err(e) = result {
return Err(Box::new(ConnectionError));
}
Ok(Store {
connection: connection.to_string()
})
}
pub fn get(&self, key: &str) -> Result<Option<String>> {
handle(&format!("{}{}{}", GET, SEP, key), &self.connection)
}
pub fn insert(&self, key: &str, value: &str) -> Result<Option<String>> {
handle(&format!("{}{}{}{}{}", INSERT, SEP, key, SEP, value), &self.connection)
}
pub fn remove(&self, key: &str) -> Result<Option<String>> {
handle(&format!("{}{}{}", REMOVE, SEP, key), &self.connection)
}
pub fn clear(&self) -> Result<Option<String>> {
handle(&format!("{}", CLEAR), &self.connection)
}
}