Skip to content
angshumanPublic

About

Rust port of HexaDb - schemaless graph database using SPO triples with full hexastore (6-way) indexing on sled

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

hexadb (Rust port)

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.

Usage

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).

Building & Testing

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).

Easiest way on Windows (strongly recommended)

Because the MSVC linker is often broken, we provide helpers that automatically use the working gnu toolchain.

1. Using just (best experience)

Install just:

scoop install just
# or
cargo install just

Then 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

2. Using make (classic, works in Git Bash / MSYS2 / WSL)

# Works in Git Bash, MSYS2, or any environment with make
make test
make test-all
make build-cli
make perf COUNT=250000

The Makefile automatically switches to the gnu toolchain on Windows, just like the justfile and PowerShell scripts.

3. Using the provided PowerShell scripts (no extra tools needed)

# 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 200000

4. Manual gnu toolchain (fallback)

cargo +stable-x86_64-pc-windows-gnu test
cargo +stable-x86_64-pc-windows-gnu run --features cli --bin hexadb -- --help

Proper long-term fix (repair MSVC)

If you want normal cargo test / cargo build --features cli to work without prefixes:

  1. Open Visual Studio Installer
  2. Modify → enable "Desktop development with C++" workload
  3. Ensure these are selected:
    • MSVC v143 - VS 2022 C++ x64/x86 build tools
    • Windows 10/11 SDK
  4. Repair
  5. Open a new PowerShell and run:
    cargo clean
    cargo test

After a successful repair, plain commands should work.

.cargo/config.toml

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.

Project Status & Fidelity (Max-Effort Update)

  • 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.rs tests (including #[ignore] 1M-scale perf test).
  • Full seek continuation + paging: Implemented in SledGraph (*_after methods using exact key encoding + ByteCompare) and QueryExecutor. Proper continuation tokens now work like the original RocksGraph overloads.
  • Reasoner: Fully ported (src/reasoner/) — SimpleReasoner with 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) or cargo build --features cli. Commands: insert, get, query, patch, perf, list. The CLI is behind the cli feature so that normal cargo 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.

License

MIT (same as original)

About

Rust port of HexaDb - schemaless graph database using SPO triples with full hexastore (6-way) indexing on sled

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages