v0.7.0

QUERY Expressions

Last updated


This page explains how QUERY filters JSON documents by field, its expression grammar, and how to build the same filters in Go.

QUERY


  1. QUERY active = true
  2. QUERY profile.level >= 3
  3. QUERY role = admin AND active = true LIMIT 20
  4. QUERY (role = admin OR role = editor) AND NOT disabled = true

Only JSON entries with a warm parsed cache are evaluated. A condition reads a dot-notation field, renders it with utils.Vtoa (so 1.0 becomes 1 and true stays true), and compares it with the operator. A missing field makes the condition false, including under NE.
Each result line is key: <raw JSON>, not just the key.

Expression Grammar


  1. expression := or
  2. or := and ( OR and )*
  3. and := not ( AND not )*
  4. not := NOT not | primary
  5. primary := "(" expression ")" | field operator value

  • AND, OR, and NOT are case-insensitive; AND binds tighter than OR.
  • Input is split on whitespace, then leading ( and trailing ) are peeled off each token, so (role and editor) work.
  • A value is one token; it cannot contain spaces.
  • Leftover tokens fail with unexpected word: ...; a missing operator, value, or ) also fails.

Programmatic Filters


  1. f := filter.And{
  2. filter.GTE{Field: "profile.level", Value: "3"},
  3. filter.Not{filter.EQ{Field: "disabled", Value: "true"}},
  4. }
  5. rows := torii.Query(f, 20)
  6. parsed, err := filter.AtoFilter("role = admin OR role = editor")

TypeKind
And, Or[]Filter
Not[1]Filter
Cond{Field, Op, Value}Generic condition
EQ, NE, GT, GTE, GE, LT, LTE, LE, LIKE{Field, Value} shorthands


中文