Skip to content

Latest commit

 

History

History
219 lines (172 loc) · 5.16 KB

query.md

File metadata and controls

219 lines (172 loc) · 5.16 KB

Querying

The query syntax is based on the Loopback query filter.

General remarks

  • All queries must be submitted as a JSON object.

  • When supplying units in a parameter query, the quantity will be converted to SI units for comparison with the value stored in the database. Before returning the results, the relevant quantity is converted to the unit supplied by the user in the query. E.g., if querying a parameter in keV, the quantity will be converted to kg m2 / s2 and compared to the SI value stored in the database. Before returning the results with the relevant quantities to the user, they will be converted to the same unit that the user provided in the query, in this case keV.


Contents

  1. Syntax
    1. Where filter
      1. General usage
      2. Operators
    2. Include filter
      1. General usage
      2. Include with match conditions
    3. Limit filter
    4. Skip filter
  2. Examples

Syntax

The query syntax is written in JSON format:

{
    "where": {
        "property": "value"
    },
    "include": [
        {
            "relation": "relatedModel",
            "scope": {
                "where": {
                    "property": "value"
                }
            }
        }
    ],
    "limit": 0,
    "skip": 0
}

Documentation on the different filters can be found below.


Where filter

The where filter is used to supply match conditions when querying data.

General usage

To test equivalence, the filter should be written on the following form:

{"where": {"property": "value"}}
  • property - the name of the model property that is being queried
  • value - the value that the property should be equal to

Operators

The filter can also be used to match other conditions than equality, and should then be written on the form of:

{"where": {"property": {"operator": "value"}}}

Text operator

The text operator can be used to query data matching a string.

{"where": {"text": "value"}}

The value will then be matched with the following fields (see Example):

Model Fields
Dataset Title
Document Title, Summary
File Name
Instrument Name, Facility
Sample Name, Description
Technique Name

Joining queries

A query can use logical and and or to join queries together. They are written on the following form:

{
    "where": {
        "and": [
            {
                "property": "value"
            },
            {
                "property": "value"
            }
        ]
    }
}
{
    "where": {
        "or": [
            {
                "property": "value"
            },
            {
                "property": "value"
            }
        ]
    }
}

Include filter

Related models may be included by using the include filter.

General usage

To include a related model, the query should be formatted in the following way:

{"include": [{"relation": "relatedModel"}]}

If you want to include additional related models, simply append them to the array, e.g.:

{"include": [{"relation": "relatedModel1"}, {"relation": "relatedModel2"}]}

Include with match conditions

To include a related model with match conditions, use the scope property:

{
    "include": [
        {
            "relation": "relatedModel",
            "scope": {
                "where": {
                    "property": "value"
                }
            }
        }
    ]
}

Similarly, to include more than one related model with match conditions:

{
    "include": [
        {
            "relation": "relatedModel1",
            "scope": {
                "where": {
                    "property": "value"
                }
            }
        },
        {
            "relation": "relatedModel2",
            "scope": {
                "where": {
                    "property": "value"
                }
            }
        }
    ]
}

Limit filter

You can limit the number of queries by adding

{"limit": 0}

to the filter. It is not necessary to include this filter if the value is 0.


Skip filter

Results can be skipped using the skip property

{"skip": 0}

It is not necessary to include this filter if the value is 0.


Examples