Crates.io | arangors-graph-exporter |
lib.rs | arangors-graph-exporter |
version | 0.0.9 |
source | src |
created_at | 2024-08-05 16:27:04.950241 |
updated_at | 2024-08-29 07:47:36.369943 |
description | Provides lightning-fast graph data access to ArangoDB |
homepage | |
repository | https://github.com/arangodb/arangors-graph-exporter |
max_upload_size | |
id | 1326214 |
size | 142,972 |
This Rust-based library provides a high-performance and parallel way to load data from ArangoDB. It supports loading both named graphs and custom graphs, with options to specify which vertex and edge attributes to load.
API Docs Stable | API Docs Main | ArangoDB Docs | ArangoDB
Add the following to your Cargo.toml
:
[dependencies]
arangors-graph-exporter = "0.0.9"
There are two different approaches to initialize the graph loader:
A named graph is a graph in ArangoDB that has a name and its graph definition is already stored in the database.
To initialize a graph loader for a named graph, use the GraphLoader::new_named
method.
use arangors_graph_exporter::{DatabaseConfiguration, DataLoadConfiguration, GraphLoader, GraphLoaderError};
async fn create_named_graph_loader() -> Result<GraphLoader, GraphLoaderError> {
let db_config = DatabaseConfiguration::new(/* parameters */);
let load_config = DataLoadConfiguration::new(/* parameters */);
let graph_name = String::from("my_named_graph");
let vertex_global_fields = Some(vec![String::from("lastname"), String::from("firstname")]);
let edge_global_fields = Some(vec![String::from("field1"), String::from("field2")]);
GraphLoader::new_named(db_config, load_config, graph_name, vertex_global_fields, edge_global_fields).await
}
A custom graph or anonymous graph is a graph that can act as a graph but does not have a name or a graph definition stored in the database.
To create a graph loader for a custom graph:
use arangors_graph_exporter::{DatabaseConfiguration, DataLoadConfiguration, GraphLoader, GraphLoaderError, CollectionInfo};
async fn create_custom_graph_loader() -> Result<GraphLoader, GraphLoaderError> {
let db_config = DatabaseConfiguration::new(/* parameters */);
let load_config = DataLoadConfiguration::new(/* parameters */);
let vertex_collections = vec![CollectionInfo::new(/* parameters */)];
let edge_collections = vec![CollectionInfo::new(/* parameters */)];
GraphLoader::new_custom(db_config, load_config, vertex_collections, edge_collections).await
}
Once the graph loader is initialized, you can load vertices and edges using the following methods:
do_vertices
: Load vertices from the graph.do_edges
: Load edges from the graph.Both methods take a closure as an argument to handle the loaded data.
If during the initialization you specified the global fields to load, the closure will receive the global fields as well.
If no global fields are specified, the closure will receive only the required fields. For vertices, the required fields are the vertex ID and the vertex key.
For edges the required fields are the from
vertex IDs and to
vertex IDs.
The closure for handling vertices takes the following arguments:
let handle_vertices = |vertex_ids: &Vec<Vec<u8>>, columns: &mut Vec<Vec<Value>>, vertex_field_names: &Vec<String>| {
// Handle vertex data
};
graph_loader.do_vertices(handle_vertices).await?;
The closure for handling edges takes the following arguments:
let handle_edges = |from_ids: &Vec<Vec<u8>>, to_ids: &Vec<Vec<u8>>, columns: &mut Vec<Vec<Value>>, edge_field_names: &Vec<String>| {
// Handle edge data
};
let edges_result = graph_loader.do_edges(handle_edges).await?;
Provide your database configuration parameters to DatabaseConfiguration::new
.
Please read the documentation for more information on the available parameters.
Configure data loading parameters with DataLoadConfiguration::new
.
Please read the documentation for more information on the available parameters.
Right now there is only one special field available. Special fields are identified by the @
prefix.
All methods return Result
types. Handle errors using Rust's standard error handling mechanisms.
The error type is GraphLoaderError
.
Example return type:
Result<(), GraphLoaderError>
match graph_loader.do_vertices(handle_vertices).await {
Ok(_) => println!("Vertices loaded successfully"),
Err(e) => eprintln!("Error loading vertices: {:?}", e),
}
This project is licensed under the MIT License.
First, see if the answer to your question can be found in the [API documentation]. If your question couldn't be solved, please feel free to pick one of those resources:
Please use GitHub for feature requests and bug reports: https://github.com/arangodb/arangors-graph-exporter/issues
Ask questions about the driver, Rust, usage scenarios, etc. on StackOverflow: https://stackoverflow.com/questions/tagged/arangodb
Chat with the community and the developers on Slack: https://arangodb-community.slack.com/
Learn more about ArangoDB with our YouTube channel: https://www.youtube.com/@ArangoDB
Follow us on X to stay up to date: https://x.com/arangodb
Find out more about our community: https://www.arangodb.com/community
Contributions are welcome! Please open an issue or submit a pull request.
This documentation provides a comprehensive overview of the API and usage of the Rust-based ArangoDB graph loader. It covers initialization, configuration, data loading, and error handling. For more detailed examples and advanced usage, please refer to the source code and additional documentation.