pub mod ql;
pub mod schema;
pub mod kv_graph_store;
pub mod mem_kv_store;
#[cfg(feature="lua")]
pub mod lua;
#[cfg(feature="derive")]
pub use gravitydb_derive::Schema;
trait GraphFilter<GIN, GOUT>
{
fn filter(&mut self, graph: GIN) -> GOUT;
}
pub trait Graph<'a, N: 'a, E> {
type NodeIterator: Iterator<Item=&'a N>;
type NeighborIterator: Iterator<Item=&'a N>;
type EdgeIterator: Iterator<Item=(&'a N, &'a N)>;
fn is_empty(&self) -> bool {
self.order() == 0
}
fn order(&self) -> usize;
fn size(&self) -> usize;
fn nodes(&'a self) -> Self::NodeIterator;
fn has_node(&self, node: &N) -> bool;
fn neighbors(&'a self, node: &N) -> Result<Self::NeighborIterator, E>;
fn degree(&self, node: &N) -> Result<usize, E>;
fn edges(&'a self) -> Self::EdgeIterator;
fn has_edge(&self, source: &N, target: &N) -> Result<bool, E>;
}
pub trait DirectedGraph<'a, N: 'a, E>: Graph<'a, N, E> {
type OutIterator: Iterator<Item = &'a N>;
type InIterator: Iterator<Item = &'a N>;
fn outgoing(&'a self, node: &N) -> Result<Self::OutIterator, E>;
fn incoming(&'a self, node: &N) -> Result<Self::InIterator, E>;
}
pub trait WeightedGraph<'a, N:'a, P, E> : Graph<'a, N, E> {
fn weight(&self, source: &'a N, target: &'a N) -> Result<Option<&P>, E>;
}
pub trait GraphBuilder<N, P, E> {
fn add_node(&mut self, node: N) -> Result<(), E>;
fn add_edge(&mut self, n1: &N, n2: &N, p: &P) -> Result<(), E>;
fn remove_node(&mut self, node: &N) -> Result<(), E>;
fn remove_edge(&mut self, n1: &N, n2: &N, p: &P) -> Result<(), E>;
}
pub enum PropertyFilter<PropKey> {
Only(PropKey),
FromTo(PropKey, PropKey),
All,
}
pub trait PropertyGraphReader<NodeKey, Node, EdgeKey, Edge, PropKey, Prop, E> {
fn nodes(&self, filter: PropertyFilter<PropKey>) -> Result<impl Iterator<Item=NodeKey>, E>;
fn edges(&self, filter: PropertyFilter<PropKey>) -> Result<impl Iterator<Item=EdgeKey>, E>;
fn properties(&self, filter: PropertyFilter<PropKey>) -> Result<impl Iterator<Item=PropKey>, E>;
fn read_node(&self, id: NodeKey) -> Result<Node, E>;
fn read_edge(&self, id: &EdgeKey) -> Result<Edge, E>;
fn read_property(&self, id: &PropKey) -> Result<Prop, E>;
}
pub trait GraphStore<NodeKey, EdgeKey, PropKey, Prop, E> {
fn create_node(&mut self, id: NodeKey, properties: &Prop) -> Result<NodeKey, E>;
fn update_node(&mut self, id: NodeKey, properties: &Prop) -> Result<NodeKey, E>;
fn delete_node(&mut self, id: NodeKey) -> Result<NodeKey, E>;
fn create_edge(&mut self, n1: NodeKey, n2: NodeKey, properties: &Prop) -> Result<EdgeKey, E>;
fn delete_edge(&mut self, id: &EdgeKey) -> Result<(), E>;
fn create_property(&mut self, properties: &Prop) -> Result<PropKey, E>;
fn delete_property(&mut self, id: &PropKey) -> Result<(), E>;
}
pub trait KVStore<E> {
fn create_bucket(&mut self, key: &[u8]) -> Result<(), E>;
fn delete_record(&mut self, key: &[u8]) -> Result<(), E>;
fn list_records(&self, from: &[u8], to: &[u8]) -> Result<Vec<Vec<u8>>, E>;
fn store_record(&mut self, key: &[u8], value: &[u8]) -> Result<(), E>;
fn fetch_record(&self, key: &[u8]) -> Result<Vec<u8>, E>;
fn exists(&self, key: &[u8]) -> Result<bool, E>;
}