Skip to main content

Module query

Module query 

Source
Expand description

A typesafe, builder-patterned Datalog query value.

Every type here is a plain immutable value that lowers to the boundary Edn the corium query engine parses. Nothing is stringly-typed: a Query is assembled from Vars, Terms, and Clauses and rendered with Query::to_edn, so a malformed query is a type error, not a parse error at execution time.

use corium_client::query::{Query, data, var, attr, gte, lit};

// [:find ?name ?age
//  :in $ ?min
//  :where [?e :person/name ?name]
//         [?e :person/age ?age]
//         [(>= ?age ?min)]]
let q = Query::find([var("name"), var("age")])
    .in_scalar(var("min"))
    .where_(data(var("e"), attr("person/name"), var("name")))
    .and(data(var("e"), attr("person/age"), var("age")))
    .and(gte(var("age"), var("min")))
    .to_edn();

Structs§

Call
A function call, built by call and completed with Call::bind.
Pattern
A data pattern, built by data and refined with Pattern::src, Pattern::tx, and Pattern::added.
Query
An immutable Datalog query value.
Var
A logic variable such as ?e. Constructed with or without the leading ?: var("e") and var("?e") are equal.

Enums§

Binding
A function-clause output binding.
Clause
A :where clause.
FindElem
A :find element: a variable, a pull expression, or an aggregate call.
Term
A term in a pattern, predicate, function, or rule position.

Functions§

agg_n
A bounded aggregate such as (min 3 ?x) or (max 5 ?x).
attr
An attribute keyword constant, e.g. attr("person/name") for :person/name. Returns an Edn usable in any Term position.
avg
The (avg ?x) aggregate.
blank
The blank term _.
call
A function call (name args...), completed with Call::bind.
count
The (count ?x) aggregate.
count_distinct
The (count-distinct ?x) aggregate.
data
A data pattern [?e :attr ?v]. Refine it with Pattern::src, Pattern::tx, or Pattern::added before adding it to a query.
eq
The predicate [(= a b)].
gt
The predicate [(> a b)].
gte
The predicate [(>= a b)].
kw
Alias for attr: a keyword constant from "ns/name" text.
lit
A constant term from any IntoEdn scalar, e.g. lit(42) or lit("hello").
lt
The predicate [(< a b)].
lte
The predicate [(<= a b)].
max
The (max ?x) aggregate.
min
The (min ?x) aggregate.
neq
The predicate [(not= a b)].
not
A (not clauses...) clause.
not_join
A (not-join [vars] clauses...) clause.
or
An (or branches...) clause. Each branch is a group of clauses joined by an implicit and.
or_join
An (or-join [vars] branches...) clause.
pred
A predicate clause [(name args...)].
pull_expr
A pull expression find element (pull ?e pattern).
rule
A rule invocation (rule-name args...).
sum
The (sum ?x) aggregate.
var
Shorthand for Var::new.