Product Development and Implementation - Yellow-Spotted-Lizard/SERLER GitHub Wiki

Search

Query Scheme

Query scheme for interaction between back- and front-end

Overall speaking, a query is represented as JSON object with a mandatory op field (means operation):

{
  "op": string,
  ...
}

Two types of queries: atomic and compound.

  • atomic: a simple query on one field with one condition, e.g. date > 2015, title match "agile". This kind of query is defined by such JSON object:

      {
        "op": string,  // operation of query, condition, from pre-defined list
        "field": string,
        "value": any,
        ...      // operation may require more than one values
      }
    

    pre-defined operations:

      + `$eq`: equals
      + `$neq`: non equals
      + `$gt`: great than
      + `$ge`: great than or equal to
      + `$lt`: little than
      + `$le`: little than or equal to
      + `$match`: a string field matches given substring, i.e. a field contains the given substring. This can be extended to regex matching
    

    examples:

    • date > 2015:

        {
          "op": "$gt",
          "field": "date",
          "value": 2015,
        }
      
    • title match "agile":

        {
          "op": "$match",
          "field": "title",
          "value": "agile",
        }
      
  • compound:

    a compound query represents logical combination (and, or, not) of queries. field is not necessary in compound queries. The scheme is

      {
        "op": "$and",  // or `"$or"`, same format
        "queries": []  // list of sub-queries
      }
    
      {
        "op": "$not",
        "query": object  // object of a query
      }
    
  • An example:

      {
          “op”: “$and”,
          “queries”: [
              {
                  “op”: “$match”,
                  “field”: “title”,
                  “value”: “tdd”
              },
              {
                  “op”: “$and”,
                  “queries”: [
                      {
                          “op”: “$ge”,
                          “field”: “date”,
                          “value”: 2009
                      },
                      {
                          “op”: “$le”,
                          “field”: “date”,
                          “value”: 2019
                      }
                  ]
              }
          ]
      }