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)
A field is also usable in getter and can be a pointer:
- to direct or nested object property, eg.
name
ordeep.nest.obj
- with type check for array or object, eg.
arr[]
ormap{}
- to array member by id, eg
arr[0]
orarr[-5]
from the end - to array or object first member that matches subfilter, eg
arr[id=123].name
ormap{id=123}.name
- to array or object length, eg
arr[@]
ormap{@}
- to object keys, eg
map{*}
List of operators:
-
=
- loose comparisons (==
)
a=1
matches to number 1, string "1" and booleantrue
,a=[ab]
case insensitive glob -
==
- strict comparisons (===
)
a==1
matches to number 1,a=="1"
matches to string "1",a==true
matches to booleantrue
,a==[ab]
case sensitive glob -
!=
,!==
,>
,>=
,<
,<=
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.
-
?field
- is Truthy -
?!field
- is Falsy -
?field=1,"a b"
- number1
or stringa b
-
?field=*[bc]*
- containtb
orc
-
?field="*[bc]*"
- is a string*[bc]*
-
?x.temp>@x.maxTemp
-x.temp
is greater thanx.maxTemp
on same object -
?x={temp>@maxTemp}
- same as previous with subfilter -
?arr[]
- have arrayarr
-
?arr[0]=="1"
- array first element is"1"
-
?arr[@]<=3
- have arrayarr
with 3 or less members -
?arr[]=1
- have array that contains1
or"1"
-
?arr[]==1
- .. contains1
-
?arr[]={a=1|b=2}
- .. contains object witha=1
orb=2
-
?arr[id=123].code==1
- first object in array with id 123 have code1
-
?map{}
- have objectmap
-
?map{@}>5
- have objectmap
with more than 5 keys
Copyright (c) 2013-2023 Lauri Rooden lauri@rooden.ee
The MIT License