Skip to content

Latest commit

 

History

History
137 lines (120 loc) · 2.37 KB

File metadata and controls

137 lines (120 loc) · 2.37 KB

Filter

Filter follow this structure:

{
    "field": "name",
    "operator": "eq",
    "value": "John"
}

You can also use a shorthand for the eq operator:

{
    "name": "John" // this is internally converted to { "field": "name", "operator": "eq", "value": "John" }
}

Multiple filters

You can use the and & or operator to combine multiple filters and create complex queries.

{
        "and": [
            {
                "field": "name",
                "operator": "eq",
                "value": "John"
            },
            {
                "field": "age",
                "operator": "gt",
                "value": 18
            }
        ]
    }
{
        "or": [
            {
                "field": "name",
                "operator": "eq",
                "value": "John"
            },
            {
                "field": "age",
                "operator": "gt",
                "value": 18
            }
        ]
    }

Examples

Normal filter

db list --where "status=done"
db list --where "status=done&author=dio"
db list --where "or[0][status]=done&or[1][author]=dio"

Filter with JSON

db list --where '{"status": "done" }' 
db list --where '{"status": "done", "author": "dio" }' 
db list --where '{"or": [{"status": "done"}, {"author": "dio"}] }' 

Filter with file

Complex filters can be a little verbose to do in a inline, so you can also use a file to express the filter.

YAML
db list --where "query.yml" # load file
# query.yml
or:
    - and:
        - field: status
          operator: eq
          value: done
        - field: author
          operator: eq
          value: dio
    - field: age
        operator: gt
        value: 18
JSON
db list --where "query.json" # load file
// query.json
{
    "or": [
        {
            "and": [
                {
                    "field": "status",
                    "operator": "eq",
                    "value": "done"
                },
                {
                    "field": "author",
                    "operator": "eq",
                    "value": "dio"
                }
            ]
        },
        {
            "field": "age",
            "operator": "gt",
            "value": 18
        }
    ]
}