1pub mod ql;
2pub mod schema;
3pub mod kv_graph_store;
4pub mod mem_kv_store;
5#[cfg(feature="lua")]
6pub mod lua;
7#[cfg(feature="derive")]
8pub use gravitydb_derive::Schema;
9
10trait GraphFilter<GIN, GOUT>
11{
12 fn filter(&mut self, graph: GIN) -> GOUT;
13}
14
15pub trait Graph<'a, N: 'a, E> {
16 type NodeIterator: Iterator<Item=&'a N>;
17 type NeighborIterator: Iterator<Item=&'a N>;
18 type EdgeIterator: Iterator<Item=(&'a N, &'a N)>;
19
20 fn is_empty(&self) -> bool;
22
23 fn order(&self) -> usize;
25
26 fn size(&self) -> usize;
28
29 fn nodes(&'a self) -> Self::NodeIterator;
31
32 fn has_node(&self, node: &N) -> bool;
34
35 fn neighbors(&'a self, node: &N) -> Result<Self::NeighborIterator, E>;
37
38 fn degree(&self, node: &N) -> Result<usize, E>;
40
41 fn edges(&'a self) -> Self::EdgeIterator;
43
44 fn has_edge(&self, source: &N, target: &N) -> Result<bool, E>;
46}
47
48pub trait DirectedGraph<'a, N: 'a, E>: Graph<'a, N, E> {
49 type OutIterator: Iterator<Item = &'a N>;
50 type InIterator: Iterator<Item = &'a N>;
51
52 fn outgoing(&'a self, node: &N) -> Result<Self::OutIterator, E>;
54
55 fn incoming(&'a self, node: &N) -> Result<Self::InIterator, E>;
57}
58
59pub trait WeightedGraph<'a, N:'a, P, E> : Graph<'a, N, E> {
60 fn weight(&self, source: &'a N, target: &'a N) -> Result<Option<&P>, E>;
62}
63
64pub trait GraphBuilder<N, P, E> {
65 fn add_node(&mut self, node: N) -> Result<(), E>;
67 fn add_edge(&mut self, n1: &N, n2: &N, p: &P) -> Result<(), E>;
72 fn remove_node(&mut self, node: &N) -> Result<(), E>;
73 fn remove_edge(&mut self, n1: &N, n2: &N, p: &P) -> Result<(), E>;
74}
75
76pub trait KVStore<E> {
81 fn create_bucket(&mut self, key: &[u8]) -> Result<(), E>;
83 fn delete_record(&mut self, key: &[u8]) -> Result<(), E>;
85 fn list_records(&self, key: &[u8]) -> Result<Vec<Vec<u8>>, E>;
87 fn store_record(&mut self, key: &[u8], value: &[u8]) -> Result<(), E>;
89 fn fetch_record(&self, key: &[u8]) -> Result<Vec<u8>, E>;
91 fn exists(&self, key: &[u8]) -> Result<bool, E>;
93}
94
95pub trait GraphStore<NodeK, Node, EdgeKey, Edge, PropKey, T, E> {
97 fn create_node(&mut self, id: NodeK, properties: &T) -> Result<NodeK, E>;
99 fn read_node(&self, id: NodeK) -> Result<Node, E>;
100 fn update_node(&mut self, id: NodeK, properties: &T) -> Result<NodeK, E>;
101 fn delete_node(&mut self, id: NodeK) -> Result<NodeK, E>;
102 fn create_edge(&mut self, n1: NodeK, n2: NodeK, properties: &T) -> Result<EdgeKey, E>;
103 fn read_edge(&self, id: &EdgeKey) -> Result<Edge, E>;
104 fn delete_edge(&mut self, id: &EdgeKey) -> Result<(), E>;
105 fn create_property(&mut self, properties: &T) -> Result<PropKey, E>;
106 fn read_property(&self, id: &PropKey) -> Result<T, E>;
107 fn delete_property(&mut self, id: &PropKey) -> Result<(), E>;
108
109 }