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
calland completed withCall::bind. - Pattern
- A data pattern, built by
dataand refined withPattern::src,Pattern::tx, andPattern::added. - Query
- An immutable Datalog query value.
- Var
- A logic variable such as
?e. Constructed with or without the leading?:var("e")andvar("?e")are equal.
Enums§
- Binding
- A function-clause output binding.
- Clause
- A
:whereclause. - Find
Elem - A
:findelement: 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 anEdnusable in anyTermposition. - avg
- The
(avg ?x)aggregate. - blank
- The blank term
_. - call
- A function call
(name args...), completed withCall::bind. - count
- The
(count ?x)aggregate. - count_
distinct - The
(count-distinct ?x)aggregate. - data
- A data pattern
[?e :attr ?v]. Refine it withPattern::src,Pattern::tx, orPattern::addedbefore 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
IntoEdnscalar, e.g.lit(42)orlit("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 implicitand. - 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.