GruPHst
An in-memory graph database.
Possible to persists on file (just because is something that we always expect from an in-memory databases).
Early state of development with lot of TODOs, just doing nerdy things with Graph Databases while trying to learn some Rust.
To run tests
$ cargo test
To run tests with debug output:
$ cargo test -- --show-output
Install
Run the following Cargo command in your project directory:
$ cargo add gruphst
Or add the following line to your Cargo.toml:
gruphst = "0.1.0"
Nodes
Creates a Node with the given name, the id is generated
use Node;
let node = new;
Updates the name of the Node
use Node;
let mut node = new;
node.update_name;
Node Attributes
Set attributes for a Node
use Node;
let mut node = new;
node.set_attr;
Get attributes for a Node
use Node;
let mut node = new;
node.set_attr;
let attr = node.get_attr.unwrap;
Returns an Array containing all attribute keys
use Node;
let mut node = new;
node.set_attr;
node.set_attr;
let keys = node.get_attr_keys;
assert!;
Updates the value of an attribute
use Node;
let mut node = new;
node.set_attr;
node.set_attr;
node.update_attr;
Updates the value of an attribute or creates a new one if attribute key does not exists
use Node;
let mut node = new;
node.set_attr;
node.upsert_attr;
assert_eq!;
node.upsert_attr;
assert_eq!;
Retrieves the lenght of attributes for a Node
use Node;
let mut node = new;
node.set_attr;
node.set_attr;
assert_eq!;
Checks if attributes for a Node is empty
use Node;
let mut node = new;
assert!;
node.set_attr;
node.set_attr;
assert!;
Deletes an attribute for a Node
use Node;
let mut node = new;
assert!;
node.set_attr;
assert!;
node.del_attr;
assert!;
Graph
Representation of a Graph, relating two nodes
Creates a Graph, the id is generated
use Node;
use Graph;
let alice = new;
let bob = new;
let alice_bob_graph =
new;
Updates the relation for the Graph
use Node;
use Graph;
let alice = new;
let bob = new;
let mut alice_bob_graph = new;
assert_eq!;
alice_bob_graph.update_relation;
assert_eq!;
Updates the "from" node in Graph
use Node;
use Graph;
let mut alice_node = new;
let bob_node = new;
let mut graph = new;
assert_eq!;
assert_eq!;
alice_node.update_name;
graph.update_from;
assert_eq!;
Updates the "to" node in Graph
use Node;
use Graph;
let alice_node = new;
let bob_node = new;
let mut graph = new;
assert_eq!;
assert_eq!;
let fred_node = new;
graph.update_to;
assert_eq!;
assert_ne!;
Graphs
A colection of Graph
Creates a new collection of Graph elements
use Graphs;
let my_graph = new;
Retrieves the length of the Graphs
use ;
let mut graphs = new;
let alice = new;
let bob = new;
graphs.add;
graphs.add;
assert_eq!;
Checks if the Graphs is empty
use ;
let mut graphs = new;
assert!;
let alice = new;
let bob = new;
graphs.add;
graphs.add;
assert!;
Updates the name of the Graphs
use Graphs;
let mut my_graph = new;
assert_eq!;
my_graph.update_name;
assert_eq!;
Adds a Graph element to the colection
use ;
let alice = new;
let bob = new;
let alice_bob_graph = new;
let mut my_graph = new;
my_graph.add;
Returns a collection of Graps elements that matches the relation
use ;
let alice = new;
let bob = new;
let alice_bob_graph = new;
let mut my_graph = new;
my_graph.add;
let result_graph = my_graph.find_by_relation.unwrap;
assert_eq!;
Returns a Graph that provided id matches with Graph, or From, To Nodes
use ;
let mut my_graph = new;
let alice = new;
let bob = new;
let alice_bob = new;
my_graph.add;
let alice_fred =
new;
my_graph.add;
let bob_node_id = bob.id;
let res = my_graph.find_by_id;
assert_eq!;
Deletes the Graph that matches with the provided id
use ;
let mut my_graph = new;
let alice = new;
let bob = new;
let alice_bob = new;
my_graph.add;
let alice_fred =
new;
my_graph.add;
assert_eq!;
my_graph.delete_graph_by_id;
assert_eq!;
Updates the Graphs with the provided one
use ;
let mut my_graphs = new;
let alice_node = new;
let bob_node = new;
let alice_bob_graph =
new;
my_graphs.add;
let fred_node = new;
let mut alice_fred_graph =
new;
my_graphs.add;
assert_eq!;
assert_eq!;
alice_fred_graph.update_relation;
my_graphs.update_graph;
assert_eq!;
let updated_graph = my_graphs.find_by_id;
assert_eq!;
Graphs Stats
Returns stats from Graphs; size in bytes, amount of graph, name, total number of attributes and total amount of Nodes
use ;
let mut my_graphs = new;
my_graphs.add;
let stats = my_graphs.stats.unwrap;
assert_eq!;
assert_eq!;
assert_eq!;
Persistence
Save to file
Saves the current Graphs into a file with the Graphs's name
use ;
let mut my_graph = new;
let alice = new;
let bob = new;
let alice_bob = new;
my_graph.add;
my_graph.persists;
Load from file
Loads the persisted Graphs on a file
use ;
let mut my_graph = new;
let alice = new;
let bob = new;
let alice_bob = new;
my_graph.add;
let _ = my_graph.persists;
let name = my_graph.name;
let file_name = format!;
let loaded_graphs = load;
match loaded_graphs
Loging
Enables logging providing a level
use enable_logging;
enable_logging;
Feedback from usage and contributions are very welcome. Also if you like it, please leave a :star: I would appreciate it ;)