Skip to main content

Module nql

Module nql 

Source
Expand description

NQL (NEDB Query Language) parser and executor for v2 DAG storage.

Grammar: FROM coll [AS OF seq] [VALID AS OF “date”] [WHERE ] [SEARCH “text”] [ORDER BY field [ASC|DESC]] [LIMIT n] [GROUP BY field COUNT|SUM|AVG|MIN|MAX] [TRACE caused_by [REVERSE]]

where is a full boolean expression:

:= := [OR ]* := [AND ]* := [NOT] := “(” “)” | := field ( = | != | > | < | >= | <= ) value | field [NOT] IN “(” value [, value]* “)” | field [NOT] BETWEEN value AND value | field [NOT] LIKE|ILIKE “pattern” | field IS [NOT] NULL

Until 3.3.0 the predicate surface was six operators wide (= != > < >= <=) joined by an implicit AND, with no grouping, no negation and no set/range/ pattern tests. Every one of those is table stakes in SQL, and their absence is the single most visible gap against a SQL engine: the queries people actually type (status IN ('open','pending'), height BETWEEN 100 AND 200, name LIKE 'ac%') had to be decomposed by hand or filtered client-side.

NOTE ON STRICTNESS. The old parser ended its clause loop with _ => { self.advance(); } — “skip unrecognised”. That is the same defect class as a swallowed write error: a query containing a clause the engine does not implement did not fail, it silently returned the results of a DIFFERENT query. FROM x WHERE a = 1 OFFSET 5 dropped both tokens and answered without the offset; a misspelled ORDRE BY height answered unsorted. Unknown tokens are now a parse error. This is deliberately breaking for queries that were already being silently misread — there was no correct behaviour to preserve.

Structs§

Aggregate
An aggregate, grouped or ungrouped.
OrderKey
One ORDER BY key. A list of these replaces the old single Option<String> + bool pair, because ORDER BY status, fee DESC — sort by one column then break ties with another — has no encoding as a single field plus a single direction.
Query

Enums§

GroupAgg
Pred
A boolean predicate tree.

Functions§

execute
node_to_json
A node as a flat query row: data fields at the top level plus the _-prefixed metadata. Public so the HTTP single-row GET returns the SAME shape a query row has — one definition, so the two surfaces cannot drift apart.
parse
Execute a NQL query against the DAG database. Parse NQL into a Query WITHOUT touching the database.
query
Parse and execute NQL, returning (rows, count).