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 self.order() == 0
23 }
24
25 fn order(&self) -> usize;
27
28 fn size(&self) -> usize;
30
31 fn nodes(&'a self) -> Self::NodeIterator;
33
34 fn has_node(&self, node: &N) -> bool;
36
37 fn neighbors(&'a self, node: &N) -> Result<Self::NeighborIterator, E>;
39
40 fn degree(&self, node: &N) -> Result<usize, E>;
42
43 fn edges(&'a self) -> Self::EdgeIterator;
45
46 fn has_edge(&self, source: &N, target: &N) -> Result<bool, E>;
48}
49
50pub trait DirectedGraph<'a, N: 'a, E>: Graph<'a, N, E> {
51 type OutIterator: Iterator<Item = &'a N>;
52 type InIterator: Iterator<Item = &'a N>;
53
54 fn outgoing(&'a self, node: &N) -> Result<Self::OutIterator, E>;
56
57 fn incoming(&'a self, node: &N) -> Result<Self::InIterator, E>;
59}
60
61pub trait WeightedGraph<'a, N:'a, P, E> : Graph<'a, N, E> {
62 fn weight(&self, source: &'a N, target: &'a N) -> Result<Option<&P>, E>;
64}
65
66pub trait GraphBuilder<N, P, E> {
67 fn add_node(&mut self, node: N) -> Result<(), E>;
69 fn add_edge(&mut self, n1: &N, n2: &N, p: &P) -> Result<(), E>;
74 fn remove_node(&mut self, node: &N) -> Result<(), E>;
75 fn remove_edge(&mut self, n1: &N, n2: &N, p: &P) -> Result<(), E>;
76}
77
78pub enum PropertyFilter<PropKey> {
80 Only(PropKey),
82 FromTo(PropKey, PropKey),
85 All,
87}
88
89pub trait PropertyGraphReader<NodeKey, Node, EdgeKey, Edge, PropKey, Prop, E> {
91 fn nodes(&self, filter: PropertyFilter<PropKey>) -> Result<impl Iterator<Item=NodeKey>, E>;
93 fn edges(&self, filter: PropertyFilter<PropKey>) -> Result<impl Iterator<Item=EdgeKey>, E>;
95 fn properties(&self, filter: PropertyFilter<PropKey>) -> Result<impl Iterator<Item=PropKey>, E>;
97
98 fn read_node(&self, id: NodeKey) -> Result<Node, E>;
100 fn read_edge(&self, id: &EdgeKey) -> Result<Edge, E>;
102 fn read_property(&self, id: &PropKey) -> Result<Prop, E>;
104
105 }
109
110pub trait GraphStore<NodeKey, EdgeKey, PropKey, Prop, E> {
112 fn create_node(&mut self, id: NodeKey, properties: &Prop) -> Result<NodeKey, E>;
114 fn update_node(&mut self, id: NodeKey, properties: &Prop) -> Result<NodeKey, E>;
115 fn delete_node(&mut self, id: NodeKey) -> Result<NodeKey, E>;
116 fn create_edge(&mut self, n1: NodeKey, n2: NodeKey, properties: &Prop) -> Result<EdgeKey, E>;
117 fn delete_edge(&mut self, id: &EdgeKey) -> Result<(), E>;
118 fn create_property(&mut self, properties: &Prop) -> Result<PropKey, E>;
119 fn delete_property(&mut self, id: &PropKey) -> Result<(), E>;
120}
121
122pub trait KVStore<E> {
127 fn create_bucket(&mut self, key: &[u8]) -> Result<(), E>;
129 fn delete_record(&mut self, key: &[u8]) -> Result<(), E>;
131 fn list_records(&self, from: &[u8], to: &[u8]) -> Result<Vec<Vec<u8>>, E>;
135 fn store_record(&mut self, key: &[u8], value: &[u8]) -> Result<(), E>;
137 fn fetch_record(&self, key: &[u8]) -> Result<Vec<u8>, E>;
139 fn exists(&self, key: &[u8]) -> Result<bool, E>;
141}