TerminusDB.WOQL (terminusdb_ex v0.3.3)

Copy Markdown View Source

A functional builder DSL for WOQL (Web Object Query Language).

WOQL is TerminusDB's Datalog-based query language. This module provides a comprehensive set of ~100 composable functions that build a TerminusDB.WOQL.Query struct, which can be serialized to the JSON-LD wire format via to_jsonld/1 and executed via TerminusDB.WOQL.execute/3.

This is WOQL DSL v0.2 (ADR-0008) extended in v0.3.2 with temporal/Allen, CSV/IO, range queries, and an RDF list library.

Design

The DSL is purely functional (no macros). Each function returns a %WOQL.Query{} struct and composes by nesting, mirroring the recommended functional WOQL style. Variables are plain strings using the v:Name convention.

The JSON-LD encoder uses four value-wrapper types matching the Python/JS clients: NodeValue (nodes/IRIs), Value (generic values), DataValue (literal data), and ArithmeticValue (arithmetic operands). Use iri/1 to explicitly mark a string as an IRI in triple object position (string objects default to xsd:string literals).

Supported vocabulary (v0.2)

Logical combinators

FunctionWOQL JSON-LD type
and_/1And
or_/1Or
not_/1Not
opt/1 (alias optional/1)Optional
once/1Once
immediately/1Immediately

Query modifiers

FunctionWOQL JSON-LD type
select/2Select
distinct/2Distinct
limit/2Limit
start/2Start
order_by/2OrderBy
group_by/4GroupBy
count/2Count
collect/3Collect
star/0, all/0Triple (shortcut)

Graph patterns

FunctionWOQL JSON-LD type
triple/3Triple
quad/4Triple + graph
added_triple/3, added_quad/4AddedTriple
removed_triple/3, removed_quad/4DeletedTriple
add_triple/3, add_quad/4AddTriple
delete_triple/3, delete_quad/4DeleteTriple
update_triple/3, update_quad/4And (macro)

Comparison

FunctionWOQL JSON-LD type
eq/2Equals
less/2Less
greater/2Greater
gte/2Gte
lte/2Lte
like/3Like

Schema ops

FunctionWOQL JSON-LD type
type_of/2TypeOf
isa/2IsA
sub/2 (alias subsumption/2)Subsumption
cast/3 (alias typecast/3)Typecast

Arithmetic

FunctionWOQL JSON-LD type
eval/2Eval
plus/1, minus/1, times/1, divide/1Plus/Minus/Times/Divide
div/1Div
exp/2Exp
floor/1Floor
sum/2Sum

String ops

FunctionWOQL JSON-LD type
concat/2 (alias concatenate/2)Concatenate
join/3Join
substr/5 (alias substring/5)Substring
trim/2Trim
upper/2Upper
lower/2Lower
pad/4Pad
split/3Split
length/2Length
regexp/3Regexp

List / Set / Dict ops

FunctionWOQL JSON-LD type
dot/3Dot
member/2Member
slice/4Slice
set_difference/3SetDifference
set_intersection/3SetIntersection
set_union/3SetUnion
set_member/2SetMember
list_to_set/2ListToSet

Path / navigation

FunctionWOQL JSON-LD type
path/3, path/4Path

Path patterns accept both string patterns (path("v:S", "friend*", "v:O")) and structured builders via TerminusDB.WOQL.Path (path_star/1, path_plus/1, path_times/3, path_seq/1, path_or/1, path_inverse/1, path_pred/1, path_any/0).

ID generation

FunctionWOQL JSON-LD type
unique/3HashKey
idgen/3 (alias idgenerator/3)LexicalKey
idgen_random/2 (alias random_idgen/2)RandomKey

Documents

FunctionWOQL JSON-LD type
read_document/2ReadDocument
insert_document/2InsertDocument
update_document/2UpdateDocument
delete_document/1DeleteDocument

Graph context

FunctionWOQL JSON-LD type
using/2Using
from/2From
into/2Into
comment/2Comment

Graph meta

FunctionWOQL JSON-LD type
size/2Size
triple_count/2TripleCount

Range queries

FunctionWOQL JSON-LD type
triple_slice/5, quad_slice/6TripleSlice
triple_slice_rev/5, quad_slice_rev/6TripleSliceRev
triple_next/4, quad_next/5TripleNext
triple_previous/4, quad_previous/5TriplePrevious

Temporal / Allen interval algebra

FunctionWOQL JSON-LD type
interval/3Interval
interval_start_duration/3IntervalStartDuration
interval_duration_end/3IntervalDurationEnd
interval_relation/5IntervalRelation
interval_relation_typed/3IntervalRelationTyped
date_duration/3DateDuration
day_after/2DayAfter
day_before/2DayBefore
weekday/2Weekday
weekday_sunday_start/2WeekdaySundayStart
iso_week/3IsoWeek
month_start_date/2MonthStartDate
month_end_date/2MonthEndDate
month_start_dates/3MonthStartDates
month_end_dates/3MonthEndDates
in_range/3InRange
sequence/5Sequence
range_min/2RangeMin
range_max/2RangeMax

CSV / IO

FunctionWOQL JSON-LD type
get/2Get
put/3Put
woql_as/1Column/Indicator (helper)
file/2QueryResource
remote/2QueryResource
post/2QueryResource

RDF list library

See TerminusDB.WOQL.RDFList for 17 RDF list manipulation functions.

Literal / value helpers

FunctionDescription
var/1Wraps a name as "v:Name"
iri/1Wraps a string as a NodeValue IRI
string/1Wraps as xsd:string literal
boolean/1Wraps as xsd:boolean literal
datetime/1Wraps as xsd:dateTime literal
date/1Wraps as xsd:date literal
literal/2Generic typed literal
true_/0True constant

Quick start

import TerminusDB.WOQL

query =
  and_([
    triple("v:Person", "rdf:type", iri("@schema:Person")),
    triple("v:Person", "name", "v:Name")
  ])

jsonld = TerminusDB.WOQL.to_jsonld(query)

# Execute against a database
config = TerminusDB.Config.new(endpoint: "http://localhost:6363")
config = TerminusDB.Config.with_database(config, "mydb")
{:ok, result} = TerminusDB.WOQL.execute(config, query)

Summary

Functions

Builds an AddTriple with a graph — adds quads.

Builds an AddTriple — adds triples matching [S, P, O].

Builds an AddedTriple with a graph — a quad added in the current commit.

Builds an AddedTriple — a triple added in the current commit.

Alias for star/0.

Builds an And conjunction of sub-queries.

Wraps a boolean as an xsd:boolean literal dict.

Builds a Typecast — casts value to type, binding to result.

Builds a Collect — collects all solutions into a list.

Builds a Comment — attaches a text comment to a sub-query.

Builds a Concatenate — concatenates a list of strings/vars into result.

Builds a Count — counts solutions of the sub-query and binds to countvar.

Wraps a Date or ISO 8601 string as an xsd:date literal dict.

Builds a DateDuration — tri-directional duration arithmetic for dates/dateTimes (end-of-month preserving).

Wraps a DateTime, NaiveDateTime, or ISO 8601 string as an xsd:dateTime literal dict.

Builds a DayAfter — computes the calendar day after the given date (bidirectional).

Builds a DayBefore — computes the calendar day before the given date (bidirectional).

Builds a DeleteDocument — delete a document by IRI.

Builds a DeleteTriple with a graph — deletes quads.

Builds a DeleteTriple — deletes triples matching [S, P, O].

Builds a Distinct — returns distinct solutions for the given variables.

Builds a Div — integer division of a list of arithmetic values.

Builds a Divide — divides a list of arithmetic values left-to-right.

Builds a Dot — accesses a dictionary field or list element.

Builds an Equals unification: left equals right.

Builds an Eval — evaluates an arithmetic expression and binds to result.

Executes a WOQL query against the database scoped in config.

Executes a WOQL query, or raises TerminusDB.Error.

Executes a WOQL query and returns a lazy Stream of binding maps.

Builds an Expbase raised to the power of exponent.

Builds a QueryResource for a file source (CSV format by default).

Builds a Floor — greatest integer ≤ value.

Builds a From — sets the default graph for the enclosed query.

Deserializes a JSON-LD WOQL query back into a WOQL.Query struct.

Builds a Get — reads a CSV/columns resource.

Builds a Greater comparison: left > right.

Builds a GroupBy — groups sub-query results by vars using template, binding into grouped.

Builds a Gte comparison: left >= right.

Builds a LexicalKey — lexical (deterministic, non-hash) ID.

Builds a RandomKey — cryptographically-secure random ID.

Builds an Immediately — run side-effects without backtracking.

Builds an InRange — tests whether value falls within half-open range [start, end).

Builds an InsertDocument — inserts a document.

Builds an Interval — constructs/deconstructs a half-open xdd:dateTimeInterval [start, end).

Builds an IntervalDurationEnd — relates interval to end endpoint and precise xsd:duration.

Builds an IntervalRelation — Allen's Interval Algebra: classifies the relationship between two half-open intervals.

Builds an IntervalRelationTyped — Allen's Interval Algebra on xdd:dateTimeInterval values.

Builds an IntervalStartDuration — relates interval to start endpoint and precise xsd:duration.

Builds an Into — sets the output graph for writing.

Wraps a string as a NodeValue IRI — use for triple objects that should be treated as IRIs rather than string literals.

Builds an IsA — true if element is a member of of_type.

Builds an IsoWeek — computes ISO 8601 week-numbering year and week number.

Builds a Join — joins a list into a string with glue.

Builds a Length — binds the length of a list.

Builds a Less comparison: left < right.

Builds a Like — string similarity with edit-distance dist.

Builds a Limit — maximum number of results.

Builds a ListToSet — converts a list to a set.

Wraps a value as a typed literal dict. The type is prefixed with xsd: if it does not already contain a colon.

Builds a Lower — converts to lowercase.

Builds an Lte comparison: left <= right.

Builds a Member — iterates members of a list.

Builds a Minus — subtracts a list of arithmetic values left-to-right.

Builds a MonthEndDate — last day of the month for a given xsd:gYearMonth (handles leap years).

Builds a MonthEndDates — generator: every last-of-month date in [start, end).

Builds a MonthStartDate — first day of the month for a given xsd:gYearMonth.

Builds a MonthStartDates — generator: every first-of-month date in [start, end).

Builds a Not negation of a sub-query.

Builds a Once — obtain only one result from the sub-query.

Builds an Optional wrapper — the sub-query is allowed to fail without invalidating the enclosing query.

Alias for opt/1.

Builds an Or disjunction of sub-queries.

Builds an OrderBy — orders results by the given variables.

Builds a Pad — pads string to length with pad.

Builds a Path query — traverses the graph from subject to object following the given pattern.

Builds a Plus — sums a list of arithmetic values.

Builds a QueryResource for a file posted as part of the request.

Builds a Put — writes an array of variables + optional column names to a resource.

Builds a Quad pattern: subject, predicate, object, graph.

Builds a TripleNext with an explicit graph selector.

Builds a TriplePrevious with an explicit graph selector.

Builds a TripleSlice with an explicit graph selector.

Builds a TripleSliceRev with an explicit graph selector.

Builds a RangeMax — find maximum value in a list (any comparable types).

Builds a RangeMin — find minimum value in a list (any comparable types).

Builds a ReadDocument that reads a document by ID into a variable.

Builds a Regexp — regex match; result_list captures groups.

Builds a QueryResource for a remote URL data source.

Builds a DeletedTriple with a graph — a quad removed in the current commit.

Builds a DeletedTriple — a triple removed in the current commit.

Builds a Select that projects the given variables from a sub-query.

Builds a Sequence — generates a sequence of values in half-open [start, end) via backtracking. step and count are optional (default nil).

Builds a SetDifference.

Builds a SetIntersection.

Builds a SetMember — membership test in a set.

Builds a Size — binds the size (bytes) of a graph.

Builds a Slice — slices a list [start, end).

Builds a Split — splits a string by glue into a list.

Builds a star query — selects everything as triples with default variables v:Subject, v:Predicate, v:Object.

Builds a Start — offset (start index) for results.

Wraps a string as an xsd:string literal dict.

Builds a Subsumption — true if child is a subclass of parent.

Builds a Substring — extracts a substring with before/length/after.

Builds a Sum — sums a list of numbers into a single value.

Builds a Times — multiplies a list of arithmetic values.

Serializes a WOQL.Query to the JSON-LD wire format expected by the /api/woql endpoint.

Builds a Trim — strips leading/trailing whitespace.

Builds a Triple pattern: subject, predicate, object.

Builds a TripleCount — binds the number of triples in a graph.

Builds a TripleNext — finds the next object value after a reference. When object is bound and next is free, finds the smallest next > object.

Builds a TriplePrevious — finds the previous object value before a reference. When object is bound and previous is free, finds the largest previous < object.

Builds a TripleSlice — triple pattern with half-open value range [low, high) on the object.

Builds a TripleSliceRev — same as triple_slice/5 but iterates in descending order (high to low).

Builds a True constant query.

Builds a TypeOf that unifies the type of a node with a variable.

Builds a HashKey — deterministic hash ID from a key list.

Builds an UpdateDocument — insert-or-replace a document.

Composes an update: optionally delete any existing quad, then add the new one.

Composes an update: optionally delete any existing triple, then add the new one. Equivalent to and_([opt(delete_triple(s, p, "v:OldObject")), add_triple(s, p, o)]).

Builds an Upper — converts to uppercase.

Builds a Using — scopes the enclosed query to a data product / collection.

Wraps a name as a WOQL variable string ("v:Name").

Builds a Weekday — computes ISO 8601 weekday number (Monday=1, Sunday=7).

Builds a WeekdaySundayStart — computes US-convention weekday (Sunday=1, Saturday=7).

Builds a list of Column/Indicator JSON-LD objects for use with get/2 and put/3.

Types

t()

@type t() :: %TerminusDB.WOQL{args: [term()], op: atom()}

value()

@type value() :: String.t() | woql_var() | number() | boolean() | map() | [value()]

woql_node()

@type woql_node() :: String.t() | woql_var()

woql_var()

@type woql_var() :: String.t()

Functions

add_quad(s, p, o, graph)

@spec add_quad(woql_node(), woql_node(), value(), String.t()) :: t()

Builds an AddTriple with a graph — adds quads.

Examples

iex> q = TerminusDB.WOQL.add_quad("v:S", "name", "Alice", "instance")
iex> q.op
:add_quad

add_triple(s, p, o)

@spec add_triple(woql_node(), woql_node(), value()) :: t()

Builds an AddTriple — adds triples matching [S, P, O].

Examples

iex> q = TerminusDB.WOQL.add_triple("v:S", "name", "Alice")
iex> q.op
:add_triple

added_quad(s, p, o, graph)

@spec added_quad(woql_node(), woql_node(), value(), String.t()) :: t()

Builds an AddedTriple with a graph — a quad added in the current commit.

Examples

iex> q = TerminusDB.WOQL.added_quad("v:S", "name", "v:N", "instance")
iex> q.op
:added_quad

added_triple(s, p, o)

@spec added_triple(woql_node(), woql_node(), value()) :: t()

Builds an AddedTriple — a triple added in the current commit.

Examples

iex> q = TerminusDB.WOQL.added_triple("v:S", "name", "v:N")
iex> q.op
:added_triple

all()

@spec all() :: t()

Alias for star/0.

and_(queries)

@spec and_([t()]) :: t()

Builds an And conjunction of sub-queries.

Examples

iex> q = TerminusDB.WOQL.and_([
...>   TerminusDB.WOQL.triple("v:S", "rdf:type", "v:T"),
...>   TerminusDB.WOQL.eq("v:T", "Person")
...> ])
iex> q.op
:and

boolean(value)

@spec boolean(boolean()) :: map()

Wraps a boolean as an xsd:boolean literal dict.

Examples

iex> TerminusDB.WOQL.boolean(true)
%{"@type" => "xsd:boolean", "@value" => true}

cast(value, type, result)

@spec cast(value(), value(), value()) :: t()

Builds a Typecast — casts value to type, binding to result.

Examples

iex> q = TerminusDB.WOQL.cast("v:Val", "xsd:integer", "v:Result")
iex> q.op
:cast

collect(template, into, query)

@spec collect(value(), value(), t()) :: t()

Builds a Collect — collects all solutions into a list.

Examples

iex> q = TerminusDB.WOQL.collect("v:Template", "v:Into",
...>   TerminusDB.WOQL.triple("v:S", "p", "v:O"))
iex> q.op
:collect

comment(text, query)

@spec comment(String.t(), t()) :: t()

Builds a Comment — attaches a text comment to a sub-query.

Examples

iex> q = TerminusDB.WOQL.comment("find friends", TerminusDB.WOQL.triple("v:S", "p", "v:O"))
iex> q.op
:comment

concat(list, result)

@spec concat([value()], value()) :: t()

Builds a Concatenate — concatenates a list of strings/vars into result.

Examples

iex> q = TerminusDB.WOQL.concat(["v:First", " ", "v:Last"], "v:Full")
iex> q.op
:concat

concatenate(list, result)

@spec concatenate([value()], value()) :: t()

Alias for concat/2.

count(countvar, query)

@spec count(woql_var(), t()) :: t()

Builds a Count — counts solutions of the sub-query and binds to countvar.

Examples

iex> q = TerminusDB.WOQL.count("v:N", TerminusDB.WOQL.triple("v:S", "p", "v:O"))
iex> q.op
:count

date(value)

@spec date(Date.t() | String.t()) :: map()

Wraps a Date or ISO 8601 string as an xsd:date literal dict.

Examples

iex> TerminusDB.WOQL.date("2026-01-15")
%{"@type" => "xsd:date", "@value" => "2026-01-15"}

date_duration(start_val, end_val, duration)

@spec date_duration(value(), value(), value()) :: t()

Builds a DateDuration — tri-directional duration arithmetic for dates/dateTimes (end-of-month preserving).

Examples

iex> q = TerminusDB.WOQL.date_duration("v:Start", "v:End", "v:Dur")
iex> q.op
:date_duration

datetime(value)

@spec datetime(DateTime.t() | NaiveDateTime.t() | String.t()) :: map()

Wraps a DateTime, NaiveDateTime, or ISO 8601 string as an xsd:dateTime literal dict.

Examples

iex> TerminusDB.WOQL.datetime("2026-01-15T10:30:00Z")
%{"@type" => "xsd:dateTime", "@value" => "2026-01-15T10:30:00Z"}

day_after(date, next_date)

@spec day_after(value(), value()) :: t()

Builds a DayAfter — computes the calendar day after the given date (bidirectional).

Examples

iex> q = TerminusDB.WOQL.day_after("v:Date", "v:Next")
iex> q.op
:day_after

day_before(date, previous)

@spec day_before(value(), value()) :: t()

Builds a DayBefore — computes the calendar day before the given date (bidirectional).

Examples

iex> q = TerminusDB.WOQL.day_before("v:Date", "v:Prev")
iex> q.op
:day_before

delete_document(iri)

@spec delete_document(woql_node()) :: t()

Builds a DeleteDocument — delete a document by IRI.

Examples

iex> q = TerminusDB.WOQL.delete_document("Person/Alice")
iex> q.op
:delete_document

delete_quad(s, p, o, graph)

@spec delete_quad(woql_node(), woql_node(), value(), String.t()) :: t()

Builds a DeleteTriple with a graph — deletes quads.

Examples

iex> q = TerminusDB.WOQL.delete_quad("v:S", "name", "v:O", "instance")
iex> q.op
:delete_quad

delete_triple(s, p, o)

@spec delete_triple(woql_node(), woql_node(), value()) :: t()

Builds a DeleteTriple — deletes triples matching [S, P, O].

Examples

iex> q = TerminusDB.WOQL.delete_triple("v:S", "name", "v:O")
iex> q.op
:delete_triple

distinct(vars, query)

@spec distinct([woql_var()], t()) :: t()

Builds a Distinct — returns distinct solutions for the given variables.

Examples

iex> q = TerminusDB.WOQL.distinct(["v:Name"], TerminusDB.WOQL.triple("v:P", "name", "v:Name"))
iex> q.op
:distinct

div(args)

@spec div([value() | t()]) :: t()

Builds a Div — integer division of a list of arithmetic values.

Examples

iex> q = TerminusDB.WOQL.div(["v:X", 5])
iex> q.op
:div

divide(args)

@spec divide([value() | t()]) :: t()

Builds a Divide — divides a list of arithmetic values left-to-right.

Examples

iex> q = TerminusDB.WOQL.divide(["v:X", 5])
iex> q.op
:divide

dot(document, field, value)

@spec dot(value(), value(), value()) :: t()

Builds a Dot — accesses a dictionary field or list element.

Examples

iex> q = TerminusDB.WOQL.dot("v:Doc", "field", "v:Value")
iex> q.op
:dot

eq(left, right)

@spec eq(value(), value()) :: t()

Builds an Equals unification: left equals right.

Examples

iex> q = TerminusDB.WOQL.eq("v:Name", "Alice")
iex> q.op
:eq

eval(expression, result)

@spec eval(t(), value()) :: t()

Builds an Eval — evaluates an arithmetic expression and binds to result.

The expression is typically a nested arithmetic query such as plus/1, minus/1, times/1, etc.

Examples

iex> q = TerminusDB.WOQL.eval(TerminusDB.WOQL.plus(["v:X", 5]), "v:Result")
iex> q.op
:eval

execute(config, query, opts \\ [])

@spec execute(TerminusDB.Config.t(), t(), keyword()) ::
  {:ok, map()} | {:error, TerminusDB.Error.t()}

Executes a WOQL query against the database scoped in config.

Returns {:ok, result} where result is a map containing bindings (a list of maps, one per solution), or {:error, TerminusDB.Error.t()}.

Options

  • :author - commit author (for write queries).
  • :message - commit message (for write queries).
  • :all_witnesses - check for all errors (default false).
  • :organization - overrides config.organization.
  • :repo - overrides config.repo.
  • :branch - overrides config.branch.

Examples

iex> config = TerminusDB.Config.new(
...>   endpoint: "http://localhost:6363",
...>   adapter: fn req ->
...>     {req, Req.Response.new(status: 200, body: %{"bindings" => [%{"Name" => "Alice"}]})}
...>   end
...> ) |> TerminusDB.Config.with_database("mydb")
iex> q = TerminusDB.WOQL.select(["v:Name"],
...>   TerminusDB.WOQL.and_([TerminusDB.WOQL.triple("v:P", "name", "v:Name")])
...> )
iex> {:ok, result} = TerminusDB.WOQL.execute(config, q)
iex> result["bindings"]
[%{"Name" => "Alice"}]

execute!(config, query, opts \\ [])

@spec execute!(TerminusDB.Config.t(), t(), keyword()) :: map()

Executes a WOQL query, or raises TerminusDB.Error.

Examples

iex> config = TerminusDB.Config.new(
...>   endpoint: "http://localhost:6363",
...>   adapter: fn req -> {req, Req.Response.new(status: 200, body: %{"bindings" => []})} end
...> ) |> TerminusDB.Config.with_database("mydb")
iex> q = TerminusDB.WOQL.triple("v:S", "p", "v:O")
iex> TerminusDB.WOQL.execute!(config, q)
%{"bindings" => []}

execute_stream(config, query, opts \\ [])

@spec execute_stream(TerminusDB.Config.t(), t(), keyword()) ::
  {:ok, Enumerable.t()} | {:error, TerminusDB.Error.t()}

Executes a WOQL query and returns a lazy Stream of binding maps.

The stream uses the PrefaceRecord/Binding/PostscriptRecord protocol for incremental delivery. Each element is a %{"@type" => "Binding", ...} map.

Options

Same as execute/3.

Examples

iex> config = TerminusDB.Config.new(
...>   endpoint: "http://localhost:6363",
...>   adapter: fn req -> {req, Req.Response.new(status: 200, body: [%{"@type" => "PrefaceRecord", "names" => ["Name"]}, %{"@type" => "Binding", "Name" => "Alice"}, %{"@type" => "PostscriptRecord"}])} end
...> ) |> TerminusDB.Config.with_database("mydb")
iex> q = TerminusDB.WOQL.select(["v:Name"], TerminusDB.WOQL.triple("v:P", "name", "v:Name"))
iex> {:ok, stream} = TerminusDB.WOQL.execute_stream(config, q)
iex> Enum.to_list(stream)
[%{"@type" => "Binding", "Name" => "Alice"}]

exp(base, exponent)

@spec exp(value() | t(), value() | t()) :: t()

Builds an Expbase raised to the power of exponent.

Examples

iex> q = TerminusDB.WOQL.exp("v:X", 2)
iex> q.op
:exp

file(fpath, opts \\ [])

@spec file(
  String.t(),
  keyword()
) :: t()

Builds a QueryResource for a file source (CSV format by default).

Examples

iex> q = TerminusDB.WOQL.file("data.csv")
iex> q.op
:file

floor(value)

@spec floor(value() | t()) :: t()

Builds a Floor — greatest integer ≤ value.

Examples

iex> q = TerminusDB.WOQL.floor("v:X")
iex> q.op
:floor

from(graph, query)

@spec from(String.t(), t()) :: t()

Builds a From — sets the default graph for the enclosed query.

Examples

iex> q = TerminusDB.WOQL.from("instance", TerminusDB.WOQL.triple("v:S", "p", "v:O"))
iex> q.op
:from

from_jsonld(jsonld)

@spec from_jsonld(map()) :: t()

Deserializes a JSON-LD WOQL query back into a WOQL.Query struct.

Examples

iex> jsonld = %{"@type" => "Triple", "subject" => %{"@type" => "NodeValue", "variable" => "S"}, "predicate" => %{"@type" => "NodeValue", "node" => "name"}, "object" => %{"@type" => "Value", "variable" => "N"}}
iex> q = TerminusDB.WOQL.from_jsonld(jsonld)
iex> q.op
:triple

get(as_vars, query_resource)

@spec get([map()], t()) :: t()

Builds a Get — reads a CSV/columns resource.

as_vars is a list of Column objects built by woql_as/1. query_resource is built by file/2, remote/2, or post/2.

Examples

iex> q = TerminusDB.WOQL.get(TerminusDB.WOQL.woql_as([{"name", "v:Name"}]), TerminusDB.WOQL.file("data.csv"))
iex> q.op
:get

greater(left, right)

@spec greater(value(), value()) :: t()

Builds a Greater comparison: left > right.

Examples

iex> q = TerminusDB.WOQL.greater("v:Age", 30)
iex> q.op
:greater

group_by(vars, template, grouped, query)

@spec group_by([woql_var()], value(), value(), t()) :: t()

Builds a GroupBy — groups sub-query results by vars using template, binding into grouped.

Examples

iex> q = TerminusDB.WOQL.group_by(["v:Type"], "v:Template", "v:Grouped",
...>   TerminusDB.WOQL.triple("v:S", "rdf:type", "v:Type"))
iex> q.op
:group_by

gte(left, right)

@spec gte(value(), value()) :: t()

Builds a Gte comparison: left >= right.

Examples

iex> q = TerminusDB.WOQL.gte("v:Age", 30)
iex> q.op
:gte

idgen(prefix, key_list, uri)

@spec idgen(String.t(), [value()], woql_var()) :: t()

Builds a LexicalKey — lexical (deterministic, non-hash) ID.

Examples

iex> q = TerminusDB.WOQL.idgen("Person/", ["v:Name"], "v:ID")
iex> q.op
:idgen

idgen_random(prefix, uri)

@spec idgen_random(String.t(), woql_var()) :: t()

Builds a RandomKey — cryptographically-secure random ID.

Examples

iex> q = TerminusDB.WOQL.idgen_random("Person/", "v:ID")
iex> q.op
:idgen_random

idgenerator(prefix, key_list, uri)

@spec idgenerator(String.t(), [value()], woql_var()) :: t()

Alias for idgen/3.

immediately(query)

@spec immediately(t()) :: t()

Builds an Immediately — run side-effects without backtracking.

Examples

iex> q = TerminusDB.WOQL.immediately(TerminusDB.WOQL.triple("v:S", "p", "v:O"))
iex> q.op
:immediately

in_range(value, start_val, end_val)

@spec in_range(value(), value(), value()) :: t()

Builds an InRange — tests whether value falls within half-open range [start, end).

Examples

iex> q = TerminusDB.WOQL.in_range("v:Val", 10, 100)
iex> q.op
:in_range

insert_document(doc, identifier \\ nil)

@spec insert_document(value(), woql_node() | nil) :: t()

Builds an InsertDocument — inserts a document.

identifier is a variable (e.g. "v:Id") that will be bound to the inserted document's IRI. TerminusDB 12 requires it for well-formed InsertDocument JSON-LD.

Examples

iex> q = TerminusDB.WOQL.insert_document("v:Doc")
iex> q.op
:insert_document

iex> q = TerminusDB.WOQL.insert_document(%{"@type" => "Person"}, "v:Id")
iex> q.op
:insert_document

interval(start_val, end_val, interval_val)

@spec interval(value(), value(), value()) :: t()

Builds an Interval — constructs/deconstructs a half-open xdd:dateTimeInterval [start, end).

Examples

iex> q = TerminusDB.WOQL.interval("v:Start", "v:End", "v:I")
iex> q.op
:interval

interval_duration_end(duration, end_val, interval_val)

@spec interval_duration_end(value(), value(), value()) :: t()

Builds an IntervalDurationEnd — relates interval to end endpoint and precise xsd:duration.

Examples

iex> q = TerminusDB.WOQL.interval_duration_end("v:Dur", "v:End", "v:I")
iex> q.op
:interval_duration_end

interval_relation(relation, x_start, x_end, y_start, y_end)

@spec interval_relation(value(), value(), value(), value(), value()) :: t()

Builds an IntervalRelation — Allen's Interval Algebra: classifies the relationship between two half-open intervals.

Examples

iex> q = TerminusDB.WOQL.interval_relation("v:Rel", "v:XS", "v:XE", "v:YS", "v:YE")
iex> q.op
:interval_relation

interval_relation_typed(relation, x, y)

@spec interval_relation_typed(value(), value(), value()) :: t()

Builds an IntervalRelationTyped — Allen's Interval Algebra on xdd:dateTimeInterval values.

Examples

iex> q = TerminusDB.WOQL.interval_relation_typed("v:Rel", "v:X", "v:Y")
iex> q.op
:interval_relation_typed

interval_start_duration(start_val, duration, interval_val)

@spec interval_start_duration(value(), value(), value()) :: t()

Builds an IntervalStartDuration — relates interval to start endpoint and precise xsd:duration.

Examples

iex> q = TerminusDB.WOQL.interval_start_duration("v:Start", "v:Dur", "v:I")
iex> q.op
:interval_start_duration

into(graph, query)

@spec into(String.t(), t()) :: t()

Builds an Into — sets the output graph for writing.

Examples

iex> q = TerminusDB.WOQL.into("schema", TerminusDB.WOQL.add_triple("v:S", "p", "v:O"))
iex> q.op
:into

iri(node)

@spec iri(String.t()) :: map()

Wraps a string as a NodeValue IRI — use for triple objects that should be treated as IRIs rather than string literals.

Examples

iex> TerminusDB.WOQL.iri("@schema:Person")
%{"@type" => "NodeValue", "node" => "@schema:Person"}

isa(element, of_type)

@spec isa(woql_node(), woql_node()) :: t()

Builds an IsA — true if element is a member of of_type.

Examples

iex> q = TerminusDB.WOQL.isa("v:X", WOQL.iri("@schema:Person"))
iex> q.op
:isa

iso_week(date, year, week)

@spec iso_week(value(), value(), value()) :: t()

Builds an IsoWeek — computes ISO 8601 week-numbering year and week number.

Examples

iex> q = TerminusDB.WOQL.iso_week("v:Date", "v:Year", "v:Week")
iex> q.op
:iso_week

join(list, glue, output)

@spec join(value(), value(), value()) :: t()

Builds a Join — joins a list into a string with glue.

Examples

iex> q = TerminusDB.WOQL.join("v:List", ", ", "v:Result")
iex> q.op
:join

length(list, len)

@spec length(value(), value()) :: t()

Builds a Length — binds the length of a list.

Examples

iex> q = TerminusDB.WOQL.length("v:List", "v:Len")
iex> q.op
:length

less(left, right)

@spec less(value(), value()) :: t()

Builds a Less comparison: left < right.

Examples

iex> q = TerminusDB.WOQL.less("v:Age", 30)
iex> q.op
:less

like(left, right, dist)

@spec like(value(), value(), value()) :: t()

Builds a Like — string similarity with edit-distance dist.

Examples

iex> q = TerminusDB.WOQL.like("v:Name", "Alice", 2)
iex> q.op
:like

limit(n, query)

@spec limit(non_neg_integer(), t()) :: t()

Builds a Limit — maximum number of results.

Examples

iex> q = TerminusDB.WOQL.limit(10, TerminusDB.WOQL.triple("v:S", "p", "v:O"))
iex> q.op
:limit

list_to_set(input, result)

@spec list_to_set(value(), value()) :: t()

Builds a ListToSet — converts a list to a set.

Examples

iex> q = TerminusDB.WOQL.list_to_set("v:List", "v:Set")
iex> q.op
:list_to_set

literal(value, type)

@spec literal(term(), String.t()) :: map()

Wraps a value as a typed literal dict. The type is prefixed with xsd: if it does not already contain a colon.

Examples

iex> TerminusDB.WOQL.literal("42", "integer")
%{"@type" => "xsd:integer", "@value" => "42"}

lower(left, right)

@spec lower(value(), value()) :: t()

Builds a Lower — converts to lowercase.

Examples

iex> q = TerminusDB.WOQL.lower("v:Input", "v:Result")
iex> q.op
:lower

lte(left, right)

@spec lte(value(), value()) :: t()

Builds an Lte comparison: left <= right.

Examples

iex> q = TerminusDB.WOQL.lte("v:Age", 30)
iex> q.op
:lte

member(item, list)

@spec member(value(), value()) :: t()

Builds a Member — iterates members of a list.

Examples

iex> q = TerminusDB.WOQL.member("v:Item", "v:List")
iex> q.op
:member

minus(args)

@spec minus([value() | t()]) :: t()

Builds a Minus — subtracts a list of arithmetic values left-to-right.

Examples

iex> q = TerminusDB.WOQL.minus(["v:X", 5])
iex> q.op
:minus

month_end_date(year_month, date)

@spec month_end_date(value(), value()) :: t()

Builds a MonthEndDate — last day of the month for a given xsd:gYearMonth (handles leap years).

Examples

iex> q = TerminusDB.WOQL.month_end_date("v:YM", "v:Date")
iex> q.op
:month_end_date

month_end_dates(date, start_val, end_val)

@spec month_end_dates(value(), value(), value()) :: t()

Builds a MonthEndDates — generator: every last-of-month date in [start, end).

Examples

iex> q = TerminusDB.WOQL.month_end_dates("v:Date", "v:Start", "v:End")
iex> q.op
:month_end_dates

month_start_date(year_month, date)

@spec month_start_date(value(), value()) :: t()

Builds a MonthStartDate — first day of the month for a given xsd:gYearMonth.

Examples

iex> q = TerminusDB.WOQL.month_start_date("v:YM", "v:Date")
iex> q.op
:month_start_date

month_start_dates(date, start_val, end_val)

@spec month_start_dates(value(), value(), value()) :: t()

Builds a MonthStartDates — generator: every first-of-month date in [start, end).

Examples

iex> q = TerminusDB.WOQL.month_start_dates("v:Date", "v:Start", "v:End")
iex> q.op
:month_start_dates

not_(query)

@spec not_(t()) :: t()

Builds a Not negation of a sub-query.

Examples

iex> q = TerminusDB.WOQL.not_(TerminusDB.WOQL.eq("v:N", "Alice"))
iex> q.op
:not

once(query)

@spec once(t()) :: t()

Builds a Once — obtain only one result from the sub-query.

Examples

iex> q = TerminusDB.WOQL.once(TerminusDB.WOQL.triple("v:S", "p", "v:O"))
iex> q.op
:once

opt(query)

@spec opt(t()) :: t()

Builds an Optional wrapper — the sub-query is allowed to fail without invalidating the enclosing query.

Examples

iex> q = TerminusDB.WOQL.opt(TerminusDB.WOQL.triple("v:S", "p", "v:O"))
iex> q.op
:opt

optional(query)

@spec optional(t()) :: t()

Alias for opt/1.

or_(queries)

@spec or_([t()]) :: t()

Builds an Or disjunction of sub-queries.

Examples

iex> q = TerminusDB.WOQL.or_([
...>   TerminusDB.WOQL.eq("v:Name", "Alice"),
...>   TerminusDB.WOQL.eq("v:Name", "Bob")
...> ])
iex> q.op
:or

order_by(specs, query)

@spec order_by([{String.t(), :asc | :desc}] | keyword(), t()) :: t()

Builds an OrderBy — orders results by the given variables.

Accepts both tuple-list and keyword-list forms:

# Tuple list
TerminusDB.WOQL.order_by([{"v:Time", :asc}, {"v:Name", :desc}], query)

# Keyword list
TerminusDB.WOQL.order_by([time: :asc, name: :desc], query)

Examples

iex> q = TerminusDB.WOQL.order_by([{"v:Name", :asc}], TerminusDB.WOQL.triple("v:S", "name", "v:Name"))
iex> q.op
:order_by

iex> q2 = TerminusDB.WOQL.order_by([name: :desc], TerminusDB.WOQL.triple("v:S", "name", "v:Name"))
iex> q2.op
:order_by

pad(input, pad, length, output)

@spec pad(value(), value(), value(), value()) :: t()

Builds a Pad — pads string to length with pad.

Examples

iex> q = TerminusDB.WOQL.pad("v:Input", "0", 10, "v:Result")
iex> q.op
:pad

path(subject, pattern, object)

@spec path(woql_node(), String.t() | tuple(), value()) :: t()

Builds a Path query — traverses the graph from subject to object following the given pattern.

The pattern can be either a string (compiled via TerminusDB.WOQL.Path) or an AST node built via the structured builders (path_star/1, path_plus/1, etc.).

String patterns

# Simple predicate
TerminusDB.WOQL.path("v:S", "friend", "v:O")

# Inverse traversal
TerminusDB.WOQL.path("v:S", "<friend", "v:O")

# Star (zero or more)
TerminusDB.WOQL.path("v:S", "friend*", "v:O")

# Plus (one or more)
TerminusDB.WOQL.path("v:S", "friend+", "v:O")

# Bounded repetition
TerminusDB.WOQL.path("v:S", "friend{1,3}", "v:O")

# Alternation
TerminusDB.WOQL.path("v:S", "friend|foe", "v:O")

# Sequence
TerminusDB.WOQL.path("v:S", "friend,location", "v:O")

# Any predicate
TerminusDB.WOQL.path("v:S", ".", "v:O")

# Grouping
TerminusDB.WOQL.path("v:S", "(friend|foe)*", "v:O")

Structured patterns

TerminusDB.WOQL.path("v:S",
  TerminusDB.WOQL.Path.path_star(TerminusDB.WOQL.Path.path_pred("friend")),
  "v:O"
)

Options

  • A 4th argument binds the path itself to a variable.

Examples

iex> q = TerminusDB.WOQL.path("v:S", "friend*", "v:O")
iex> q.op
:path

iex> q2 = TerminusDB.WOQL.path("v:S", "friend*", "v:O", "v:Path")
iex> q2.args
["v:S", {:star, {:pred, "friend"}}, "v:O", "v:Path"]

path(subject, pattern, object, path_var)

@spec path(woql_node(), String.t() | tuple(), value(), woql_var()) :: t()

plus(args)

@spec plus([value() | t()]) :: t()

Builds a Plus — sums a list of arithmetic values.

Examples

iex> q = TerminusDB.WOQL.plus(["v:X", 5, "v:Y"])
iex> q.op
:plus

post(fpath, opts \\ [])

@spec post(
  String.t(),
  keyword()
) :: t()

Builds a QueryResource for a file posted as part of the request.

Examples

iex> q = TerminusDB.WOQL.post("upload.csv")
iex> q.op
:post

put(as_vars, query, query_resource)

@spec put([map()], t(), t()) :: t()

Builds a Put — writes an array of variables + optional column names to a resource.

Examples

iex> q = TerminusDB.WOQL.put(TerminusDB.WOQL.woql_as([{"name", "v:Name"}]), TerminusDB.WOQL.triple("v:S", "p", "v:O"), TerminusDB.WOQL.file("out.csv"))
iex> q.op
:put

quad(s, p, o, graph)

@spec quad(woql_node(), woql_node(), value(), String.t()) :: t()

Builds a Quad pattern: subject, predicate, object, graph.

Quads reuse the Triple JSON-LD type with an added graph field.

Examples

iex> q = TerminusDB.WOQL.quad("v:S", "name", "v:N", "instance")
iex> q.op
:quad

quad_next(subject, predicate, object, next_val, graph)

@spec quad_next(woql_node(), woql_node(), value(), value(), String.t()) :: t()

Builds a TripleNext with an explicit graph selector.

Examples

iex> q = TerminusDB.WOQL.quad_next("v:S", "v:P", "v:O", "v:Next", "instance")
iex> q.op
:triple_next

quad_previous(subject, predicate, object, prev_val, graph)

@spec quad_previous(woql_node(), woql_node(), value(), value(), String.t()) :: t()

Builds a TriplePrevious with an explicit graph selector.

Examples

iex> q = TerminusDB.WOQL.quad_previous("v:S", "v:P", "v:O", "v:Prev", "instance")
iex> q.op
:triple_previous

quad_slice(subject, predicate, object, low, high, graph)

@spec quad_slice(woql_node(), woql_node(), value(), value(), value(), String.t()) ::
  t()

Builds a TripleSlice with an explicit graph selector.

Examples

iex> q = TerminusDB.WOQL.quad_slice("v:S", "v:P", "v:O", 10, 100, "instance")
iex> q.op
:triple_slice

quad_slice_rev(subject, predicate, object, low, high, graph)

@spec quad_slice_rev(woql_node(), woql_node(), value(), value(), value(), String.t()) ::
  t()

Builds a TripleSliceRev with an explicit graph selector.

Examples

iex> q = TerminusDB.WOQL.quad_slice_rev("v:S", "v:P", "v:O", 10, 100, "instance")
iex> q.op
:triple_slice_rev

random_idgen(prefix, uri)

@spec random_idgen(String.t(), woql_var()) :: t()

Alias for idgen_random/2.

range_max(input_list, result)

@spec range_max(value(), value()) :: t()

Builds a RangeMax — find maximum value in a list (any comparable types).

Examples

iex> q = TerminusDB.WOQL.range_max("v:List", "v:Max")
iex> q.op
:range_max

range_min(input_list, result)

@spec range_min(value(), value()) :: t()

Builds a RangeMin — find minimum value in a list (any comparable types).

Examples

iex> q = TerminusDB.WOQL.range_min("v:List", "v:Min")
iex> q.op
:range_min

read_document(id, var)

@spec read_document(String.t(), woql_var()) :: t()

Builds a ReadDocument that reads a document by ID into a variable.

Examples

iex> q = TerminusDB.WOQL.read_document("Person/Alice", "v:Doc")
iex> q.op
:read_document

regexp(pattern, string, result_list)

@spec regexp(value(), value(), value()) :: t()

Builds a Regexp — regex match; result_list captures groups.

Examples

iex> q = TerminusDB.WOQL.regexp("pattern", "v:String", "v:Result")
iex> q.op
:regexp

remote(uri, opts \\ [])

@spec remote(
  String.t(),
  keyword()
) :: t()

Builds a QueryResource for a remote URL data source.

Examples

iex> q = TerminusDB.WOQL.remote("https://example.com/data.csv")
iex> q.op
:remote

removed_quad(s, p, o, graph)

@spec removed_quad(woql_node(), woql_node(), value(), String.t()) :: t()

Builds a DeletedTriple with a graph — a quad removed in the current commit.

Examples

iex> q = TerminusDB.WOQL.removed_quad("v:S", "name", "v:N", "instance")
iex> q.op
:removed_quad

removed_triple(s, p, o)

@spec removed_triple(woql_node(), woql_node(), value()) :: t()

Builds a DeletedTriple — a triple removed in the current commit.

Examples

iex> q = TerminusDB.WOQL.removed_triple("v:S", "name", "v:N")
iex> q.op
:removed_triple

select(vars, query)

@spec select([woql_var()], t()) :: t()

Builds a Select that projects the given variables from a sub-query.

vars is a list of variable names (e.g. ["v:Name", "v:Person"]).

Examples

iex> q = TerminusDB.WOQL.select(["v:Name"],
...>   TerminusDB.WOQL.and_([
...>     TerminusDB.WOQL.triple("v:Person", "name", "v:Name")
...>   ])
...> )
iex> q.op
:select

sequence(value, start_val, end_val, step \\ nil, count \\ nil)

@spec sequence(value(), value(), value(), value() | nil, value() | nil) :: t()

Builds a Sequence — generates a sequence of values in half-open [start, end) via backtracking. step and count are optional (default nil).

Examples

iex> q = TerminusDB.WOQL.sequence("v:V", 1, 10)
iex> q.op
:sequence

set_difference(list_a, list_b, result)

@spec set_difference(value(), value(), value()) :: t()

Builds a SetDifference.

Examples

iex> q = TerminusDB.WOQL.set_difference("v:A", "v:B", "v:Result")
iex> q.op
:set_difference

set_intersection(list_a, list_b, result)

@spec set_intersection(value(), value(), value()) :: t()

Builds a SetIntersection.

Examples

iex> q = TerminusDB.WOQL.set_intersection("v:A", "v:B", "v:Result")
iex> q.op
:set_intersection

set_member(element, set)

@spec set_member(value(), value()) :: t()

Builds a SetMember — membership test in a set.

Examples

iex> q = TerminusDB.WOQL.set_member("v:Item", "v:Set")
iex> q.op
:set_member

set_union(list_a, list_b, result)

@spec set_union(value(), value(), value()) :: t()

Builds a SetUnion.

Examples

iex> q = TerminusDB.WOQL.set_union("v:A", "v:B", "v:Result")
iex> q.op
:set_union

size(graph, size_var)

@spec size(String.t(), value()) :: t()

Builds a Size — binds the size (bytes) of a graph.

Examples

iex> q = TerminusDB.WOQL.size("instance", "v:Size")
iex> q.op
:size

slice(input, result, start, end_val \\ nil)

@spec slice(value(), value(), value(), value() | nil) :: t()

Builds a Slice — slices a list [start, end).

Examples

iex> q = TerminusDB.WOQL.slice("v:List", "v:Result", 0, 5)
iex> q.op
:slice

split(input, glue, output)

@spec split(value(), value(), value()) :: t()

Builds a Split — splits a string by glue into a list.

Examples

iex> q = TerminusDB.WOQL.split("v:String", ",", "v:Result")
iex> q.op
:split

star()

@spec star() :: t()

Builds a star query — selects everything as triples with default variables v:Subject, v:Predicate, v:Object.

Examples

iex> q = TerminusDB.WOQL.star()
iex> q.op
:triple

start(n, query)

@spec start(non_neg_integer(), t()) :: t()

Builds a Start — offset (start index) for results.

Examples

iex> q = TerminusDB.WOQL.start(5, TerminusDB.WOQL.triple("v:S", "p", "v:O"))
iex> q.op
:start

string(value)

@spec string(String.t()) :: map()

Wraps a string as an xsd:string literal dict.

Examples

iex> TerminusDB.WOQL.string("hello")
%{"@type" => "xsd:string", "@value" => "hello"}

sub(parent, child)

@spec sub(woql_node(), woql_node()) :: t()

Builds a Subsumption — true if child is a subclass of parent.

Examples

iex> q = TerminusDB.WOQL.sub(WOQL.iri("@schema:Animal"), WOQL.iri("@schema:Dog"))
iex> q.op
:sub

substr(string, length, substring, before \\ 0, after_ \\ 0)

@spec substr(value(), value(), value(), value(), value()) :: t()

Builds a Substring — extracts a substring with before/length/after.

Examples

iex> q = TerminusDB.WOQL.substr("v:String", 5, "v:Sub", 0, 0)
iex> q.op
:substr

substring(string, length, substring, before \\ 0, after_ \\ 0)

@spec substring(value(), value(), value(), value(), value()) :: t()

Alias for substr/5.

subsumption(parent, child)

@spec subsumption(woql_node(), woql_node()) :: t()

Alias for sub/2.

sum(list, result)

@spec sum(value(), value()) :: t()

Builds a Sum — sums a list of numbers into a single value.

Examples

iex> q = TerminusDB.WOQL.sum("v:List", "v:Result")
iex> q.op
:sum

times(args)

@spec times([value() | t()]) :: t()

Builds a Times — multiplies a list of arithmetic values.

Examples

iex> q = TerminusDB.WOQL.times(["v:X", 5])
iex> q.op
:times

to_jsonld(query)

@spec to_jsonld(t()) :: map()

Serializes a WOQL.Query to the JSON-LD wire format expected by the /api/woql endpoint.

Examples

iex> q = TerminusDB.WOQL.triple("v:S", "name", "v:N")
iex> jsonld = TerminusDB.WOQL.to_jsonld(q)
iex> jsonld["@type"]
"Triple"

trim(untrimmed, trimmed)

@spec trim(value(), value()) :: t()

Builds a Trim — strips leading/trailing whitespace.

Examples

iex> q = TerminusDB.WOQL.trim("v:Untrimmed", "v:Trimmed")
iex> q.op
:trim

triple(subject, predicate, object)

@spec triple(woql_node(), woql_node(), value()) :: t()

Builds a Triple pattern: subject, predicate, object.

Any argument can be a variable ("v:Name") or a constant.

Examples

iex> q = TerminusDB.WOQL.triple("v:Person", "name", "v:Name")
iex> q.op
:triple

triple_count(graph, count_var)

@spec triple_count(String.t(), value()) :: t()

Builds a TripleCount — binds the number of triples in a graph.

Examples

iex> q = TerminusDB.WOQL.triple_count("instance", "v:Count")
iex> q.op
:triple_count

triple_next(subject, predicate, object, next_val)

@spec triple_next(woql_node(), woql_node(), value(), value()) :: t()

Builds a TripleNext — finds the next object value after a reference. When object is bound and next is free, finds the smallest next > object.

Examples

iex> q = TerminusDB.WOQL.triple_next("v:S", "v:P", "v:O", "v:Next")
iex> q.op
:triple_next

triple_previous(subject, predicate, object, prev_val)

@spec triple_previous(woql_node(), woql_node(), value(), value()) :: t()

Builds a TriplePrevious — finds the previous object value before a reference. When object is bound and previous is free, finds the largest previous < object.

Examples

iex> q = TerminusDB.WOQL.triple_previous("v:S", "v:P", "v:O", "v:Prev")
iex> q.op
:triple_previous

triple_slice(subject, predicate, object, low, high)

@spec triple_slice(woql_node(), woql_node(), value(), value(), value()) :: t()

Builds a TripleSlice — triple pattern with half-open value range [low, high) on the object.

Examples

iex> q = TerminusDB.WOQL.triple_slice("v:S", "v:P", "v:O", 10, 100)
iex> q.op
:triple_slice

triple_slice_rev(subject, predicate, object, low, high)

@spec triple_slice_rev(woql_node(), woql_node(), value(), value(), value()) :: t()

Builds a TripleSliceRev — same as triple_slice/5 but iterates in descending order (high to low).

Examples

iex> q = TerminusDB.WOQL.triple_slice_rev("v:S", "v:P", "v:O", 10, 100)
iex> q.op
:triple_slice_rev

true_()

@spec true_() :: t()

Builds a True constant query.

Examples

iex> q = TerminusDB.WOQL.true_()
iex> q.op
:true

type_of(node, var)

@spec type_of(woql_node(), woql_var()) :: t()

Builds a TypeOf that unifies the type of a node with a variable.

Examples

iex> q = TerminusDB.WOQL.type_of("v:Person", "v:Type")
iex> q.op
:type_of

typecast(value, type, result)

@spec typecast(value(), value(), value()) :: t()

Alias for cast/3.

unique(prefix, key_list, uri)

@spec unique(String.t(), [value()], woql_var()) :: t()

Builds a HashKey — deterministic hash ID from a key list.

Examples

iex> q = TerminusDB.WOQL.unique("Person/", ["v:Name", "v:Email"], "v:ID")
iex> q.op
:unique

update_document(doc, identifier \\ nil)

@spec update_document(value(), woql_node() | nil) :: t()

Builds an UpdateDocument — insert-or-replace a document.

identifier is a variable (e.g. "v:Id") that will be bound to the updated document's IRI.

Examples

iex> q = TerminusDB.WOQL.update_document("v:Doc")
iex> q.op
:update_document

iex> q = TerminusDB.WOQL.update_document(%{"@type" => "Person"}, "v:Id")
iex> q.op
:update_document

update_quad(s, p, o, graph)

@spec update_quad(woql_node(), woql_node(), value(), String.t()) :: t()

Composes an update: optionally delete any existing quad, then add the new one.

The internal variable "v:OldObject" is used to match any existing object before deletion. Avoid using "v:OldObject" as a variable in surrounding queries to prevent unintended unification.

Examples

iex> q = TerminusDB.WOQL.update_quad("v:S", "name", "Alice", "instance")
iex> q.op
:and

update_triple(s, p, o)

@spec update_triple(woql_node(), woql_node(), value()) :: t()

Composes an update: optionally delete any existing triple, then add the new one. Equivalent to and_([opt(delete_triple(s, p, "v:OldObject")), add_triple(s, p, o)]).

The internal variable "v:OldObject" is used to match any existing object before deletion. Avoid using "v:OldObject" as a variable in surrounding queries to prevent unintended unification.

Examples

iex> q = TerminusDB.WOQL.update_triple("v:S", "name", "Alice")
iex> q.op
:and

upper(left, right)

@spec upper(value(), value()) :: t()

Builds an Upper — converts to uppercase.

Examples

iex> q = TerminusDB.WOQL.upper("v:Input", "v:Result")
iex> q.op
:upper

using(collection, query)

@spec using(String.t(), t()) :: t()

Builds a Using — scopes the enclosed query to a data product / collection.

Examples

iex> q = TerminusDB.WOQL.using("mydb", TerminusDB.WOQL.triple("v:S", "p", "v:O"))
iex> q.op
:using

var(name)

@spec var(String.t()) :: String.t()

Wraps a name as a WOQL variable string ("v:Name").

Examples

iex> TerminusDB.WOQL.var("Person")
"v:Person"

weekday(date, weekday_val)

@spec weekday(value(), value()) :: t()

Builds a Weekday — computes ISO 8601 weekday number (Monday=1, Sunday=7).

Examples

iex> q = TerminusDB.WOQL.weekday("v:Date", "v:Day")
iex> q.op
:weekday

weekday_sunday_start(date, weekday_val)

@spec weekday_sunday_start(value(), value()) :: t()

Builds a WeekdaySundayStart — computes US-convention weekday (Sunday=1, Saturday=7).

Examples

iex> q = TerminusDB.WOQL.weekday_sunday_start("v:Date", "v:Day")
iex> q.op
:weekday_sunday_start

woql_as(specs)

@spec woql_as([{String.t() | non_neg_integer(), woql_var()}]) :: [map()]

Builds a list of Column/Indicator JSON-LD objects for use with get/2 and put/3.

Accepts a list of {name_or_index, variable} tuples.

Examples

iex> cols = TerminusDB.WOQL.woql_as([{"name", "v:Name"}, {0, "v:Idx"}])
iex> length(cols)
2
iex> hd(cols)["@type"]
"Column"