Skip to Content

Query builder

The query model, its conversions and its text form.

QueryBuilder edits a QueryGroup from src/lib/query.ts. In a view it is part of the FilterBar, see Filters.

The grouped buildervariant="builder" shows the advanced view in place, for a saved view's settings or a dialog. A group nests one level, with its own and/or.
Open the example ↗

The model

A query is a group of rules joined by AND or OR, with groups one level deep. Each rule has a field, an operator and a value. Fields are typed by a schema, QueryField.

Field typeOperators
textcontains, notContains, is, isNot, isEmpty, isNotEmpty
numberis, isNot, gt, gte, lt, lte, between, isEmpty, isNotEmpty
dateis, before, after, between, withinLast, isEmpty, isNotEmpty
enum, person, relationis, isNot, anyOf, noneOf, isEmpty, isNotEmpty
booleanis

A field with multiple holds a list of references, and has no empty tests.

Conversions

  • toWhere turns a query into a structured where filter.
  • Text contains comes back as a residual, for matchQuery.
  • Relative dates resolve against now.
  • fromWhere reads a where filter back.

The text form

parseQueryText and printQueryText read and write the text form of a query bar. parseQueryText(printQueryText(q)) gives q back.

TextMeaning
field:valueis
field:a,bis any of
-field:valueis not, or is none of
field:>3, >=, <, <=Comparisons
field:1..5is between
field:-7dis within the last 7 days
field:none, field:anyis empty, is not empty
field:yes, field:noA boolean
Free wordsThe text field must contain them

The result is one AND group. The text form has no OR.

Chips in a filter barA chip per rule opens a popover to edit it; Filter adds one, the sliders button opens the grouped builder and its text form. Arrow keys move between chips, Delete removes one. Assignee uses a picker of its own (renderPicker). Below, the store's where it maps to.
Open the example ↗
On a phoneChips scroll sideways under the search field, Filter first. A chip or Filter opens one sheet of grouped rows: a page per rule with its condition and value; swipe a rule to remove it.
Open the example ↗
Query builder in the gallery ↗
Edit on GitHub

Last updated on

On this page