Skip to content

Query String

Lauri Rooden edited this page Nov 30, 2020 · 1 revision

LiteJS data layer comes with powerful quering features. Same queries can be used with http requests to backend and with cached model in UI.

Typical URL containing a query string is as follows:

http://example.com/items?name=ferret
                         └┬─┘│└──┬─┘
               field ─────┘  │   └───── value
            operator ────────┘

Query strings can be combined and grouped, eg. ?name=1&(a>1|b<2)

Field

A field is also usable in getter and can be a pointer:

  • to direct or nested object property, eg. name or deep.nest.obj
  • with type check for array or object, eg. arr[] or map{}
  • to array member by id, eg arr[0] or arr[-5] from the end
  • to array or object first member that matches subfilter, eg arr[id=123].name or map{id=123}.name
  • to array or object length, eg arr[@] or map{@}
  • to object keys, eg map{*}

Operator

List of operators:

  • = - loose comparisons (==)
    a=1 matches to number 1, string "1" and boolean true, a=[ab] case insensitive glob
  • == - strict comparisons (===)
    a==1 matches to number 1, a=="1" matches to string "1", a==true matches to boolean true, a==[ab] case sensitive glob
  • !=, !==, >, >=, <, <=

Value

A value can be:

  • loose value, eg. 1,ab,true,null
  • a string, eg. "ab","true","null"
  • a glob, eg a[bc]*?
    • * matches 0 or more characters
    • ? matches 1 character
    • […] matches a range of characters. If the first character of the range is ! or ^ then it matches any character not in the range.
    • in strict comparison glob is case sensitive
  • a subfilter, eg, {type=x}
  • a pointer to another value, eg. @other.nested.value

Multiple values can be combined with a comma ,, eg. i=1,2. A strict comparisons with a glob is case sensitive, a loose comparisons is case insensitive.

Examples

  • ?field - is Truthy
  • ?!field - is Falsy
  • ?field=1,"a b" - number 1 or string a b
  • ?field=*[bc]* - containt b or c
  • ?field="*[bc]*" - is a string *[bc]*
  • ?x.temp>@x.maxTemp - x.temp is greater than x.maxTemp on same object
  • ?x={temp>@maxTemp} - same as previous with subfilter
  • ?arr[] - have array arr
  • ?arr[0]=="1" - array first element is "1"
  • ?arr[@]<=3 - have array arr with 3 or less members
  • ?arr[]=1 - have array that contains 1 or "1"
  • ?arr[]==1 - .. contains 1
  • ?arr[]={a=1|b=2} - .. contains object with a=1 or b=2
  • ?arr[id=123].code==1 - first object in array with id 123 have code 1
  • ?map{} - have object map
  • ?map{@}>5 - have object map with more than 5 keys