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.
- Basic Usage
- Install
- Tests & Coverage & Benchmarking
- Configuration
- Save & Load
- Export & Import
- Cryptography
- Examples
Basic Usage
use ;
use Error;
// The idea it's to create some graph related with
// the Middle-Earth, relating some characters and
// places
Install
Run the following Cargo command in your project directory:
$ cargo add gruphst
Or add the following line to your Cargo.toml:
gruphst = "0.15.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.
Configuration
GruPHst uses dotenv to deal with configurations. You can place a .env file in order to handle your configuration values or you can use environment variables instead to run your binary. The environmental variables will override the configuration from .env file.
e.g. override log level in your binary:
$ GRUPHST_LOG_LEVEL=trace cargo run
This is the currnet .env file:
# limit for memory usage in MB
=100
# log level, case insensitive, possible values:
# trace
# debug
# info
# warn
# warning
# err
# error
=info
# delimiter character for CSV import-export
=;
Configurable variables
Maximum memory usage
Configures the maximum memory in MB that GruPHst will use. In case that this limit will reach, before panic will persists the current status.
GRUPHST_MAX_MEM_USAGE=100
Level for logging
Sets the level for logging in case insensitive, the possible values are:
- trace
- debug
- info
- warn
- warning
- err
- error
GRUPHST_LOG_LEVEL=info
In order to use it on your binary:
// import from config and logger level
use get_log_level;
use enable_logging;
// get the configured log level; on .env file or environmental
let log_level = get_log_level;
// enable logging
enable_logging;
Character delimiter for CSV file
Configures the character used to import and export for CSV format.
GRUPHST_CSV_DELIMITER=;
Save & Load
You can persists the data on a file in GruPHst format. And later load the saved data.
use Graphs;
use Edge;
use Vertex;
let mut graphs = init;
let foo = new;
let bar = new;
graphs.add_edge;
// persists the graphs data on file,
// with "./to_export.grphst"
graphs.save;
// load the saved data
let saved_graphs = load.unwrap;
Export & Import
CSV
The delimiter could be configured with GRUPHST_CSV_DELIMITER variable, via .env file or with environmental var usage. The default character is ';'.
File Format
Headers:
graphs_vault;from_label;from_attributes;relation;to_label;to_attributes
Row example:
shire-friendships;gandalf;known as: Gandalf the Gray | name: Gandalf;friend of;frodo;name: Frodo Bolson
Note: The different attributes are separated by '|' character and key followed by ':' and vaule.
Export & Import Usage
use Graphs;
use Edge;
use Vertex;
use *;
let mut graphs = init;
let foo = new;
let bar = new;
graphs.add_edge;
// export graphs to CSV file
export_to_csv_gruphst_format.unwrap;
// import graphs from CSV file
let graphs: Graphs = import_from_csv_gruphst_format.unwrap;
Graphviz
Exports graphs to Graphviz format for visualization. Right now only export has been implemented only with type digraph non strict and no layout. The exported file can be visualize e.g. here.
The exported file with format *.gv.txt, for the bellow example is something like:
digraph {
bar [label="bar" tooltip=""];
foo [label="foo" tooltip=""];
foo -> bar [label="is related to"];
}
And visualized on the mentioned page something like:

Export Usage
use Graphs;
use Edge;
use Vertex;
use *;
let mut graphs = init;
let foo = new;
let bar = new;
graphs.add_edge;
// export graphs to Graphviz file
export_to_graphviz_format.unwrap;
Cryptography
Argon2 Hashes
You can use Argon2 to store passwords or whatever sensible data you are dealing with, and verify it.
use Vertex;
// create a vertex
let mut vertex = new;
// set an Argon2 hash
vertex.set_hash;
// Check if the provided value is valid
assert!;
assert!;
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 ;)