Difference between revisions of "LavishScript:Select"

From Lavish Software Wiki
Jump to navigation Jump to search
 
Line 6: Line 6:
  
 
== Defining a Select 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).
+
A Select Query is defined by a JSON object with any of the following parameters (all of them are optional, except those required by specific operations).
  
 
{| border="1" style="border-collapse:collapse" cellpadding="5"
 
{| border="1" style="border-collapse:collapse" cellpadding="5"
Line 24: Line 24:
 
|-
 
|-
 
! limit
 
! limit
| ''Used only by SelectKeys and SelectValues queries'', a number specifying the maximum number of results to produce
+
| ''Optionally used only by SelectKeys and SelectValues queries'', a number specifying the maximum number of results to produce
 
|-
 
|-
 
! n
 
! n
| ''Used only by SelectKey and SelectValue queries'', a number specifying that the nth matching key or value should be selected
+
| ''Optionally used only by SelectKey and SelectValue queries'', a number specifying that the nth matching key or value should be selected
 +
|-
 +
! value
 +
| ''Required by Comparison operations'', a value to compare the to
 +
|-
 +
! list
 +
| ''Required by Grouping operations'', an array of nested Select Queries
 +
|-
 +
! select
 +
| ''Required by the Negation operation'', a single nested Select Query
 
|}
 
|}
  

Latest revision as of 21:29, 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, except those required by specific operations).

Select Query properties
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
limit Optionally used only by SelectKeys and SelectValues queries, a number specifying the maximum number of results to produce
n Optionally used only by SelectKey and SelectValue queries, a number specifying that the nth matching key or value should be selected
value Required by Comparison operations, a value to compare the to
list Required by Grouping operations, an array of nested Select Queries
select Required by the Negation operation, a single nested Select Query

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
           }
       ]
   }