Expand description
Datafox is a standalone Datalog parser and streaming query engine for facts.
The crate is intentionally small: callers provide facts through Storage,
parse read-only queries with parse_query or parse_queries, and evaluate
them with a DatafoxClient configured for the runtime profile you need.
use datafox::{DatafoxClient, DatafoxConfig, InMemoryStorage, Value, parse_query};
let storage = InMemoryStorage::from_facts([(
"edge".to_string(),
vec![
vec![Value::integer(1), Value::integer(2)],
vec![Value::integer(2), Value::integer(3)],
],
)]);
let query = parse_query("edge(From, 2)")?;
let datafox = DatafoxClient::new(DatafoxConfig::new(&storage))?;
let results = datafox.eval(&query)?.collect::<Vec<_>>();
assert_eq!(results.len(), 1);
assert_eq!(results[0].lookup("From"), Some(&Value::integer(1)));Public API:
Valuefor Datalog constants.Termfor variables, constants, and wildcards.Atom,Clause, andQueryfor query syntax trees.Diagnosticandparse_queryfor query parsing with context.format_queryandformat_queriesfor stable, readable query files.SubstitutionandUnifierfor binding and matching query variables.DatafoxClient,DatafoxConfig,DatafoxEnvironment,PreparedQuery,PreparedQueryStorage,Planner,Plan, andStoragefor snapshot-based query execution.Prelude,BinaryRelation, andBinaryOperatorfor ambient facts, builtin relations, and expression operators.ErrorandResultfor typed failures.atom!,var!,lit!, andsubst!for test and call-site ergonomics.
Re-exports§
Modules§
Macros§
Structs§
- Atom
- A predicate applied to a list of terms.
- Binary
Operator - Binary
Relation - Datafox
Client - Datafox
Config - Datafox
Environment - Datafox
Environment Builder - Diagnostic
- One contextual parser or analyzer diagnostic.
- Evaluation
- Iterator over substitutions produced by an evaluator run.
- Fact
Estimate - Fact
Request - Fact
Request Hints - InMemory
Prepared Query Storage - InMemory
Storage - Planner
- Prelude
- Prepared
Query - Prepared
Query Key - Span
- One source span in an input query string.
- Substitution
- A deterministic mapping from variable names to concrete values.
- Unifier
- Stateless helpers for unification and atom-to-tuple matching.
- Universe
- A read-only query snapshot over a storage backend.
Enums§
- Atom
Role - Clause
- One clause in a query body.
- Evaluation
Strategy - Fact
Request Mode - Fact
Scan - Operator
Outcome - Pattern
Value - Projection
- Query
- A read-only Datalog query.
- Relation
Outcome - Snapshot
Selector - Term
- One Datalog term.
- Value
- Concrete constant values that can appear in Datalog facts and queries.
Constants§
Traits§
- Fact
Store - Prepared
Query Storage - Storage
- Snapshot-oriented read-only storage interface for Datalog queries.