GruPHst
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.
Documentation
Code Coverage
Basic Usage
use gruphst::{edge::Edge, graphs::Graphs, vertex::Vertex};
use std::error::Error;
fn main() -> Result<(), Box<dyn Error>> {
let frodo = Vertex::new("Frodo");
let mut gandalf = Vertex::new("Gandalf");
gandalf.set_attr("known as", "The Gray");
gandalf.set_attr("years old", 24000);
let mut edge = Edge::create(&gandalf, "friend of", &frodo);
edge.set_attr("duration in years", 42);
let mut graphs = Graphs::init("middle-earth");
graphs.add_edge(&edge, None);
graphs.add_edge(&Edge::create(&frodo, "has best friend", &gandalf), None);
let mut sam = Vertex::new("Samwise");
sam.set_attr("surname", "Gamgee");
graphs.add_edge(
&Edge::create(
&sam,
"has best friend",
&frodo),
None);
let mut vertex = Vertex::new("The Shire");
let id_vertex_the_shire = vertex.get_id();
graphs.add_edge(&Edge::create(&frodo, "lives at", &vertex), None);
vertex = Vertex::new("Isengard");
vertex.set_attr("type", "tower");
graphs.add_edge(&Edge::create(&Vertex::new("Saruman"), "lives at", &vertex), None);
let the_shire = graphs.find_vertex_by_id(id_vertex_the_shire.as_str(), None)?;
graphs.add_edge(&Edge::create(&sam, "lives at", &the_shire), None);
let stats = graphs.get_stats();
println!("{:#?}", stats);
assert_eq!(stats.get_total_vertices(), 12);
println!("{:#?}", graphs);
let unique_relations_vertices = graphs.uniq_relations();
assert_eq!(unique_relations_vertices, vec!["friend of", "has best friend", "lives at"]);
let vertices_with_relation_in = graphs.has_relation_in("lives at", None)?;
assert_eq!(vertices_with_relation_in[0].get_label(), "The Shire");
assert_eq!(vertices_with_relation_in[1].get_label(), "Isengard");
let found = graphs.attr_equals_to("years old", 24000, None)?;
assert_eq!(found[0].get_from_vertex().get_label(), "Gandalf");
graphs.persists()?;
Ok(())
}
Install
Run the following Cargo command in your project directory:
$ cargo add gruphst
Or add the following line to your Cargo.toml:
gruphst = "0.12.0"
Tests & Coverage & Benchmarking
To run tests locally
This will show output, if a test name is provided as argument will run this tests
$ ./scripts/local-test.sh
If nodemon is installed, you can use the tests in watch mode:
$ ./scripts/dev-watch.sh
Coverage
$ ./scripts/test-coverage.sh
It will generate a report called tarpauling-report.html
Benchmarking
$ ./scripts/benchmarking.sh
Right now only covers add_edge method.
Examples
Check the Rock Paper Scissors Spock Lizard example.
Check the Middle-Earth example.
Also worth to check the tests folder.
Thanks @ChrisMcMStone for all the help and memory tips ;-)
Feedback from usage and contributions are very welcome.
Also if you like it, please leave a :star: I would appreciate it ;)