use crate::atoms::IndexAtom;
use super::{prop_val_sub_index::propvalsub_key, val_prop_sub_index::valpropsub_key};
#[derive(Debug)]
pub enum Tree {
Resources,
QueryMembers,
WatchedQueries,
PropValSub,
ValPropSub,
}
const RESOURCES: &str = "resources_v1";
const VALPROPSUB: &str = "reference_index_v1";
const QUERY_MEMBERS: &str = "members_index";
const PROPVALSUB: &str = "prop_val_sub_index";
const QUERIES_WATCHED: &str = "watched_queries";
impl std::fmt::Display for Tree {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Tree::Resources => f.write_str(RESOURCES),
Tree::WatchedQueries => f.write_str(QUERIES_WATCHED),
Tree::PropValSub => f.write_str(PROPVALSUB),
Tree::ValPropSub => f.write_str(VALPROPSUB),
Tree::QueryMembers => f.write_str(QUERY_MEMBERS),
}
}
}
impl AsRef<[u8]> for Tree {
fn as_ref(&self) -> &[u8] {
match self {
Tree::Resources => RESOURCES.as_bytes(),
Tree::WatchedQueries => QUERIES_WATCHED.as_bytes(),
Tree::PropValSub => PROPVALSUB.as_bytes(),
Tree::ValPropSub => VALPROPSUB.as_bytes(),
Tree::QueryMembers => QUERY_MEMBERS.as_bytes(),
}
}
}
#[derive(Debug)]
pub enum Method {
Insert,
Delete,
}
#[derive(Debug)]
pub struct Operation {
pub tree: Tree,
pub method: Method,
pub key: Vec<u8>,
pub val: Option<Vec<u8>>,
}
impl Operation {
pub fn remove_atom_from_reference_index(index_atom: &IndexAtom) -> Self {
Operation {
tree: Tree::ValPropSub,
method: Method::Delete,
key: valpropsub_key(index_atom),
val: None,
}
}
pub fn remove_atom_from_prop_val_sub_index(index_atom: &IndexAtom) -> Self {
Operation {
tree: Tree::PropValSub,
method: Method::Delete,
key: propvalsub_key(index_atom),
val: None,
}
}
}
pub type Transaction = Vec<Operation>;