A Rust port of angshuman/hexadb — a schemaless graph database based on the Hexastore (6-way SPO indexing) approach.
Key preserved from original:
- SPO triple model with
Triple+TripleObject(IDs vs data literals + JTokenType + array index) - Synthetic IDs for nested objects using
#delimiter (e.g.parent#childprop#0) - Full 6 access patterns (S / P / O / SP / PO / OS) via 3 physical indexes
- JSON document ↔ triple round-tripping (with cycle guard)
- JSON-merge style patch + triple-level patch (retract by (s,p,index) then assert)
- Query model with property filters (eq/gt/ge/lt/le/contains) + outgoing/incoming path (
/-separated or*) or level-based graph traversal
Storage choice: sled (pure-Rust embeddable LSM) instead of RocksDB for dramatically simpler cross-platform builds (especially Windows) while keeping identical indexing strategy and prefix-scan query patterns.
The web API / ASP.NET / EventHub replication parts are not ported (per request). The library exposes clean functions + structs.
use hexadb::{Store, JsonValue};
use serde_json::json;
let store = Store::open("./data", "myapp")?;
let docs = json!([
{
"id": "sensor:0",
"type": "sensor",
"temperature": 64.44,
"marker": { "status": "running", "green": 9.85 }
}
]);
store.insert(&docs)?;
let obj = store.get("sensor:0")?.unwrap();
println!("{}", obj);
// Patch (JSON Merge Patch style)
let patch = json!({"id": "sensor:0", "name": "New name", "marker": {"status": null, "red": 1.0}});
store.patch_json(&patch)?;
// Advanced query (filter + outgoing path)
use hexadb::Query;
let q = Query {
filter: Some([("type".to_string(), hexadb::QueryUnit { op: "eq".into(), value: json!("room") })].into()),
has_object: Some(vec![ hexadb::LinkQuery {
path: "sensors/marker".into(),
level: 0,
target: hexadb::Query { filter: Some([("green".into(), hexadb::QueryUnit{op:"gt".into(), value: json!(9)})].into()), ..Default::default() }
}]),
..Default::default()
};
let resp = hexadb::QueryExecutor::new(&store, /* graph */).query(&q)?;See src/lib.rs tests and source for more (MemoryGraph also available for unit tests / embedding).
The library builds and tests cleanly on Windows with the default msvc target as long as you have a basic Rust installation.
The CLI binary pulls in clap + several Windows crates that have build scripts requiring the full MSVC linker (C++ Build Tools).
Because the MSVC linker is often broken, we provide helpers that automatically use the working gnu toolchain.
Install just:
scoop install just
# or
cargo install justThen run simple commands:
just test
just test-all # includes the big 1M-scale perf test
just build
just build-cli
just run-cli -- --help
just perf 250000# Works in Git Bash, MSYS2, or any environment with make
make test
make test-all
make build-cli
make perf COUNT=250000The Makefile automatically switches to the gnu toolchain on Windows, just like the justfile and PowerShell scripts.
# Run tests
.\scripts\test.ps1
# Run tests including ignored perf tests
.\scripts\test.ps1 -- --ignored
# Build library only
.\scripts\build.ps1
# Build with CLI support
.\scripts\build.ps1 -Cli
# Run the CLI
.\scripts\run-cli.ps1 -- --help
# Quick perf test
.\scripts\perf.ps1 -Count 200000cargo +stable-x86_64-pc-windows-gnu test
cargo +stable-x86_64-pc-windows-gnu run --features cli --bin hexadb -- --helpIf you want normal cargo test / cargo build --features cli to work without prefixes:
- Open Visual Studio Installer
- Modify → enable "Desktop development with C++" workload
- Ensure these are selected:
- MSVC v143 - VS 2022 C++ x64/x86 build tools
- Windows 10/11 SDK
- Repair
- Open a new PowerShell and run:
cargo clean cargo test
After a successful repair, plain commands should work.
We also ship a .cargo/config.toml with useful defaults and documentation about the Windows toolchain situation. You generally don't need to edit it, but it can be a place to add project-wide rustflags, aliases, or target-specific settings in the future.
- All major test scenarios ported: Converter, SPO queries, continuation (seek), patch-by-index, incoming/outgoing/level/path queries, StoreProcessor-style flows, etc. See
src/lib.rstests (including#[ignore]1M-scale perf test). - Full seek continuation + paging: Implemented in
SledGraph(*_aftermethods using exact key encoding + ByteCompare) andQueryExecutor. Proper continuation tokens now work like the originalRocksGraphoverloads. - Reasoner: Fully ported (
src/reasoner/) —SimpleReasonerwith inverseOf / domain / range / subClassOf / subPropertyOf forward chaining using data + meta + infer graphs (DisjointUnion semantics available via the module). - CLI binary:
cargo run --features cli --bin hexadb(recommended) orcargo build --features cli. Commands:insert,get,query,patch,perf,list. The CLI is behind theclifeature so that normalcargo test/ library builds do not pull heavy Windows dependencies. - Perf with 1M+ triples:
cargo run --bin hexadb -- perf myperfstore --count 100000- Dedicated ignored test:
cargo test perf_1m_triples_and_queries -- --ignored --nocapture
- Storage: sled (production-usable). Reasoner + multi-graph (data/meta/infer) ready for integration.
- Exact RocksDB bytes: not identical (sled), but indexing strategy, key layout, and all 6 patterns are faithful.
On a properly set-up Windows machine (Rust + C++ Build Tools workload) everything including the CLI builds with the default msvc target.
This completes the "all tests must be ported + reasoner + cli + full continuation + 1M perf" request.
MIT (same as original)