Skip to main content

Crate helix_db

Crate helix_db 

Source
Expand description

§helix-db Rust SDK

The helix-db crate (imported as helix_db) is the Rust SDK for HelixDB. It pairs a query-builder DSL with a small async HTTP client (Client) for running those queries against a Helix instance.

§Crate layout

  • dsl — the query-builder DSL: traversals, predicates, batches, and the DynamicQueryRequest payload type. This is the bulk of the public API.
  • query_generator — query-bundle generation, used to emit deployable stored queries from #[register]-annotated builders.
  • The crate root (Client, QueryBuilder, QueryRequest, HelixError) — the async execution surface that sends DSL queries over HTTP.

§The DSL

The DSL is centered on two entry points — read_batch for read-only transactions and write_batch for write-capable ones. You attach one or more named traversals (each usually starting with g) via .var_as(...), then choose the result payload with .returning(...):

use helix_db::dsl::prelude::*;

let query = read_batch()
    .var_as(
        "user",
        g().n_where(SourcePredicate::eq("username", "alice")),
    )
    .var_as(
        "friends",
        g().n(NodeRef::var("user")).out(Some("FOLLOWS")).dedup().limit(100),
    )
    .returning(["user", "friends"]);

Most application code only needs this curated builder API, so bring the prelude into scope:

use helix_db::dsl::prelude::*;

§Running queries

Build a Client, then use its fluent request builder. Pick a query kind — dynamic to POST an inline DynamicQueryRequest to /v1/query, or stored to call a deployed query at /v1/query/<name> — and await the response:

use helix_db::Client;
use helix_db::dsl::prelude::*;
use serde::Deserialize;

#[derive(Deserialize)]
struct Friends { friends: Vec<u64> }

let client = Client::new(Some("https://cluster.helix-db.com"))?
    .with_api_key(Some("hx_your_api_key"));

let response: Friends = client.query().dynamic(request).send().await?;

See Client for the full request-building surface (header toggles, request bodies, error handling).

Re-exports§

pub use dsl::prelude;
pub use dsl::*;

Modules§

dsl
HelixDB Query Guide
query_generator

Structs§

Client
Async HTTP client for running queries against a Helix instance.
QueryBuilder
Fluent builder for a single request, produced by Client::query.
QueryRequest
A fully addressed request, ready to send.

Enums§

HelixError
Errors returned while building or executing a query request.

Type Aliases§

HelixDBClient
Backwards-compatible alias for Client.