Difference between revisions of "LavishScript:Select"
Jump to navigation
Jump to search
(Created page with "LavishScript:Select is the next generation of LavishScript's LavishScript:Object Queries, which are deprecated but will remain as-is. ; The most obvious benefits in...") |
|||
Line 18: | Line 18: | ||
|- | |- | ||
! eval | ! eval | ||
− | | A string specifying a LavishScript Data Sequence ('''excluding <tt>${}</tt>'''). Use ''' | + | | A string specifying a LavishScript Data Sequence ('''excluding <tt>${}</tt>'''). Use '''Select''' to refer to the object/member being tested. e.g. <tt>Select.Get[name]</tt> |
|- | |- | ||
! op | ! op | ||
Line 34: | Line 34: | ||
== Examples == | == Examples == | ||
=== Example 1 === | === Example 1 === | ||
− | In this example, a JSON object is being tested against, and it has an "id" property. The following Query is equivalent to '''<tt>if ${ | + | In this example, a JSON object is being tested against, and it has an "id" property. The following Query is equivalent to '''<tt>if ${Select.Get[id]}==9012 || ${This.Select[id]}<2000</tt>''' |
{ | { | ||
− | "eval":" | + | "eval":"Select.Get[id]", |
"op":"||", | "op":"||", | ||
"list":[ | "list":[ |
Revision as of 17:37, 25 September 2022
Select is the next generation of LavishScript's Object Queries, which are deprecated but will remain as-is.
- The most obvious benefits include...
- Custom syntax eliminated in favor of using JSON to describe the query
- No need to pre-define and register/free a query
Defining a Select Query
A Select Query is defined by a JSON object with any of the following parameters (all of them are optional).
Select Query properties | |
---|---|
null | A boolean value (true/false) indicating whether a null value is a match (false by default) |
member | A string specifying the name of a Member, optionally with an args array of parameters for the Member, to use (prior to eval, op, with). Not used by default. |
eval | A string specifying a LavishScript Data Sequence (excluding ${}). Use Select to refer to the object/member being tested. e.g. Select.Get[name] |
op | A string specifying an operation to perform, one of: == != < > <= >= ! && ||. Each operation has at least one further required property, described below. |
with | An array of additional Select Queries |
Operations
- Comparison operations == != < > <= >= require a value parameter, specifying a value to compare to.
- Grouping operations && || require a list parameter, specifying an array of nested Select Queries. Each operation is executed in order, until a short-circuit condition is met (e.g. any test within an OR operation is TRUE, or any test within an AND operation is FALSE)
- Negation operation ! requires a select parameter, specifying a single nested Select Query
Examples
Example 1
In this example, a JSON object is being tested against, and it has an "id" property. The following Query is equivalent to if ${Select.Get[id]}==9012 || ${This.Select[id]}<2000
{ "eval":"Select.Get[id]", "op":"||", "list":[ { "op":"==", "value":9012 }, { "op":"<", "value":2000 } ] }