| Crates.io | graph_d |
| lib.rs | graph_d |
| version | 1.3.2 |
| created_at | 2026-01-17 17:01:16.753328+00 |
| updated_at | 2026-01-19 08:08:20.096272+00 |
| description | A native graph database implementation in Rust with built-in JSON support and SQLite-like simplicity |
| homepage | https://github.com/your-org/graph_d |
| repository | https://github.com/your-org/graph_d |
| max_upload_size | |
| id | 2050777 |
| size | 1,155,282 |
A high-performance, memory-efficient native graph database implementation in Rust with built-in JSON support and ACID compliance.
Build a production-ready, memory-efficient native graph database that leverages Rust's safety guarantees and performance characteristics to provide:
Add to your Cargo.toml:
[dependencies]
graph_d = "0.1.0"
use graph_d::{Graph, Result};
use serde_json::json;
fn main() -> Result<()> {
// Create a new in-memory graph
let mut graph = Graph::new()?;
// Create nodes with JSON properties
let alice_id = graph.create_node([
("name".to_string(), json!("Alice")),
("age".to_string(), json!(30)),
("role".to_string(), json!("Engineer")),
].into())?;
let bob_id = graph.create_node([
("name".to_string(), json!("Bob")),
("age".to_string(), json!(25)),
("role".to_string(), json!("Designer")),
].into())?;
// Create relationships
let rel_id = graph.create_relationship(
alice_id,
bob_id,
"WORKS_WITH".to_string(),
[("since".to_string(), json!("2023"))].into(),
)?;
// Query the graph
if let Some(alice) = graph.get_node(alice_id)? {
println!("Alice: {:?}", alice.properties);
}
// Find Alice's relationships
let relationships = graph.get_relationships_for_node(alice_id)?;
println!("Alice has {} relationships", relationships.len());
Ok(())
}
Graph_D also provides a standalone CLI binary for interactive database exploration, similar to sqlite3.
# Install from crates.io (includes CLI)
cargo install graph_d --features cli
# Or build from source
cargo build --release --features cli
# Start with in-memory database
graph_d
# Open or create a database file
graph_d mydb.graphd
# Execute a single query and exit
graph_d mydb.graphd -c "MATCH (n:Person) RETURN n"
# Run queries from a script file
graph_d mydb.graphd -f queries.gql
# Table format (default) - human-readable
graph_d -c "MATCH (n) RETURN n LIMIT 5" -o table
# JSON format - for programmatic processing
graph_d -c "MATCH (n) RETURN n" -o json
# CSV format - for data export
graph_d -c "MATCH (n) RETURN n.name, n.age" -o csv
When in interactive mode, these commands are available:
| Command | Description |
|---|---|
.help |
Show help message |
.exit or .quit |
Exit the shell |
.mode |
Show available output modes |
.stats |
Show database statistics |
$ graph_d mydb.graphd
Graph_D 0.1.0 - Type .help for help, .exit to exit
graph_d> CREATE (n:Person {name: 'Alice', age: 30});
1 row returned
graph_d> CREATE (n:Person {name: 'Bob', age: 25});
1 row returned
graph_d> MATCH (n:Person) RETURN n.name, n.age;
name | age
------+----
Alice | 30
Bob | 25
2 rows returned
graph_d> .exit
Goodbye!
Tested on modern hardware with realistic workloads:
| Operation | Performance | Notes |
|---|---|---|
| Node Creation | 140K-150K/sec | With JSON properties |
| Node Lookup | 32M/sec | O(1) hash map access |
| Relationship Creation | 100K/sec | With validation |
| Graph Traversal | ~12-14ฮผs | 2-hop traversal |
| Memory Usage | ~1.9KB/node | Including relationships |
use graph_d::query::{QueryBuilder, AggregateFunction};
let all_employees: Vec<_> = (1..=100).collect();
let query = QueryBuilder::new(&graph, all_employees);
// Count employees
let count = query.aggregate(AggregateFunction::Count)?;
// Average salary
let avg_salary = query.aggregate(AggregateFunction::Avg("salary".to_string()))?;
// Group by department
let groups = query.aggregate(AggregateFunction::GroupBy("department".to_string()))?;
use graph_d::query::{SortCriteria, Pagination};
// Sort by multiple criteria
let sorted = QueryBuilder::new(&graph, all_nodes)
.sort(vec![
SortCriteria::asc("department"),
SortCriteria::desc("salary"),
])?
.nodes()?;
// Paginated results
let page = query.sorted_page(
vec![SortCriteria::asc("name")],
Pagination::new(0, 10)
)?;
use graph_d::query::QueryBuilder;
// Find friends of friends
let friends_of_friends = QueryBuilder::from_node(&graph, alice_id)
.outgoing("FRIENDS_WITH")?
.outgoing("FRIENDS_WITH")?
.nodes()?;
// Filter by properties
let senior_engineers = QueryBuilder::new(&graph, all_employees)
.filter_by_property("department", &json!("Engineering"))?
.filter_by_property("level", &json!("Senior"))?
.nodes()?;
use graph_d::transaction::{TransactionManager, IsolationLevel, LockableResource};
let tx_manager = TransactionManager::new(IsolationLevel::ReadCommitted);
// Create concurrent transaction
let mut tx = tx_manager.begin_concurrent();
// Acquire locks
tx.read_lock(LockableResource::Node(1))?;
tx.write_lock(LockableResource::Node(2))?;
// Perform operations...
// Commit (automatically releases locks)
tx.commit()?;
// Create persistent database
let mut graph = Graph::open("my_graph.db")?;
// Use normally...
graph.create_node(properties)?;
// Flush to disk
graph.storage.flush()?;
// Data persists across restarts
let graph2 = Graph::open("my_graph.db")?;
The examples/ directory contains comprehensive demonstrations:
getting_started.rs - Basic usage and quick startpersistent_storage.rs - File-based persistenceadvanced_queries.rs - Complex query operationsconcurrent_transactions.rs - Multi-threaded usagegql_demo.rs - GQL query language examplesmemory_management.rs - Memory allocation patternsperformance_test.rs - Benchmarking and profilingcli_scripting.gql - GQL script file for batch operationscli_automation.sh - Shell script for CLI automationRun Rust examples with:
cargo run --example getting_started
cargo run --example persistent_storage
cargo run --example concurrent_transactions
Run CLI examples with:
# Build CLI first
cargo build --features cli
# Run GQL script
./target/debug/graph_d mydb.graphd -f examples/cli_scripting.gql
# Run automation script
chmod +x examples/cli_automation.sh
./examples/cli_automation.sh
Run the comprehensive test suite:
# All tests
cargo test
# Benchmarks
cargo bench
# With output
cargo test -- --nocapture
Contributions are welcome! Please read our Contributing Guide and follow the Code of Conduct.
git clone https://github.com/your-org/graph_d
cd graph_d
cargo test
cargo run --example advanced_queries
Licensed under either of:
at your option.
Built with โค๏ธ using:
Graph_D - Native graph database performance with Rust reliability. ๐ฆ๐