mirror of https://github.com/dapr/docs.git
statestore query api: simplify query JSON (#2061)
Signed-off-by: Dmitry Shmulevich <dmitry.shmulevich@gmail.com>
This commit is contained in:
parent
7deff4f04e
commit
32559ec186
|
@ -25,7 +25,7 @@ You can find additional information in the [related links]({{< ref "#related-lin
|
|||
## Querying the state
|
||||
|
||||
You submit query requests via HTTP POST/PUT or gRPC.
|
||||
The body of the request is the JSON map with 3 entries: `filter`, `sort`, and `pagination`.
|
||||
The body of the request is the JSON map with 3 entries: `filter`, `sort`, and `page`.
|
||||
|
||||
The `filter` is an optional section. It specifies the query conditions in the form of a tree of key/value operations, where the key is the operator and the value is the operands.
|
||||
|
||||
|
@ -42,7 +42,7 @@ If `filter` section is omitted, the query returns all entries.
|
|||
|
||||
The `sort` is an optional section and is an ordered array of `key:order` pairs, where `key` is a key in the state store, and the `order` is an optional string indicating sorting order: `"ASC"` for ascending and `"DESC"` for descending. If omitted, ascending order is the default.
|
||||
|
||||
The `pagination` is an optional section containing `limit` and `token` parameters. `limit` sets the page size. `token` is an iteration token returned by the component, and is used in subsequent queries.
|
||||
The `page` is an optional section containing `limit` and `token` parameters. `limit` sets the page size. `token` is an iteration token returned by the component, and is used in subsequent queries.
|
||||
|
||||
For some background understanding, this query request is translated into the native query language and executed by the state store component.
|
||||
|
||||
|
@ -87,17 +87,15 @@ First, let's find all employees in the state of California and sort them by thei
|
|||
This is the [query](../query-api-examples/query1.json):
|
||||
```json
|
||||
{
|
||||
"query": {
|
||||
"filter": {
|
||||
"EQ": { "value.state": "CA" }
|
||||
},
|
||||
"sort": [
|
||||
{
|
||||
"key": "value.person.id",
|
||||
"order": "DESC"
|
||||
}
|
||||
]
|
||||
}
|
||||
"filter": {
|
||||
"EQ": { "value.state": "CA" }
|
||||
},
|
||||
"sort": [
|
||||
{
|
||||
"key": "value.person.id",
|
||||
"order": "DESC"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -186,10 +184,8 @@ Let's now find all employees from the "Dev Ops" and "Hardware" organizations.
|
|||
This is the [query](../query-api-examples/query2.json):
|
||||
```json
|
||||
{
|
||||
"query": {
|
||||
"filter": {
|
||||
"IN": { "value.person.org": [ "Dev Ops", "Hardware" ] }
|
||||
}
|
||||
"filter": {
|
||||
"IN": { "value.person.org": [ "Dev Ops", "Hardware" ] }
|
||||
}
|
||||
}
|
||||
```
|
||||
|
@ -228,36 +224,34 @@ This is the [query](../query-api-examples/query3.json):
|
|||
|
||||
```json
|
||||
{
|
||||
"query": {
|
||||
"filter": {
|
||||
"OR": [
|
||||
{
|
||||
"EQ": { "value.person.org": "Dev Ops" }
|
||||
},
|
||||
{
|
||||
"AND": [
|
||||
{
|
||||
"EQ": { "value.person.org": "Finance" }
|
||||
},
|
||||
{
|
||||
"IN": { "value.state": [ "CA", "WA" ] }
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"sort": [
|
||||
"filter": {
|
||||
"OR": [
|
||||
{
|
||||
"key": "value.state",
|
||||
"order": "DESC"
|
||||
"EQ": { "value.person.org": "Dev Ops" }
|
||||
},
|
||||
{
|
||||
"key": "value.person.id"
|
||||
"AND": [
|
||||
{
|
||||
"EQ": { "value.person.org": "Finance" }
|
||||
},
|
||||
{
|
||||
"IN": { "value.state": [ "CA", "WA" ] }
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"pagination": {
|
||||
"limit": 3
|
||||
]
|
||||
},
|
||||
"sort": [
|
||||
{
|
||||
"key": "value.state",
|
||||
"order": "DESC"
|
||||
},
|
||||
{
|
||||
"key": "value.person.id"
|
||||
}
|
||||
],
|
||||
"page": {
|
||||
"limit": 3
|
||||
}
|
||||
}
|
||||
```
|
||||
|
@ -336,40 +330,52 @@ The pagination token is used "as is" in the [subsequent query](../query-api-exam
|
|||
|
||||
```json
|
||||
{
|
||||
"query": {
|
||||
"filter": {
|
||||
"OR": [
|
||||
{
|
||||
"EQ": { "value.person.org": "Dev Ops" }
|
||||
},
|
||||
{
|
||||
"AND": [
|
||||
{
|
||||
"EQ": { "value.person.org": "Finance" }
|
||||
},
|
||||
{
|
||||
"IN": { "value.state": [ "CA", "WA" ] }
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"sort": [
|
||||
"filter": {
|
||||
"OR": [
|
||||
{
|
||||
"key": "value.state",
|
||||
"order": "DESC"
|
||||
"EQ": { "value.person.org": "Dev Ops" }
|
||||
},
|
||||
{
|
||||
"key": "value.person.id"
|
||||
"AND": [
|
||||
{
|
||||
"EQ": { "value.person.org": "Finance" }
|
||||
},
|
||||
{
|
||||
"IN": { "value.state": [ "CA", "WA" ] }
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"pagination": {
|
||||
"limit": 3,
|
||||
"token": "3"
|
||||
]
|
||||
},
|
||||
"sort": [
|
||||
{
|
||||
"key": "value.state",
|
||||
"order": "DESC"
|
||||
},
|
||||
{
|
||||
"key": "value.person.id"
|
||||
}
|
||||
],
|
||||
"page": {
|
||||
"limit": 3,
|
||||
"token": "3"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
{{< tabs "HTTP API (Bash)" "HTTP API (PowerShell)" >}}
|
||||
{{% codetab %}}
|
||||
```bash
|
||||
curl -s -X POST -H "Content-Type: application/json" -d @query-api-examples/query3-token.json http://localhost:3500/v1.0-alpha1/state/statestore/query | jq .
|
||||
```
|
||||
{{% /codetab %}}
|
||||
{{% codetab %}}
|
||||
```powershell
|
||||
Invoke-RestMethod -Method Post -ContentType 'application/json' -InFile query-api-examples/query3-token.json -Uri 'http://localhost:3500/v1.0-alpha1/state/statestore/query'
|
||||
```
|
||||
{{% /codetab %}}
|
||||
{{< /tabs >}}
|
||||
|
||||
And the result of this query is:
|
||||
```json
|
||||
{
|
||||
|
|
|
@ -1,13 +1,11 @@
|
|||
{
|
||||
"query": {
|
||||
"filter": {
|
||||
"EQ": { "value.state": "CA" }
|
||||
},
|
||||
"sort": [
|
||||
{
|
||||
"key": "value.person.id",
|
||||
"order": "DESC"
|
||||
}
|
||||
]
|
||||
}
|
||||
"filter": {
|
||||
"EQ": { "value.state": "CA" }
|
||||
},
|
||||
"sort": [
|
||||
{
|
||||
"key": "value.person.id",
|
||||
"order": "DESC"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
{
|
||||
"query": {
|
||||
"filter": {
|
||||
"IN": { "value.person.org": [ "Dev Ops", "Hardware" ] }
|
||||
}
|
||||
"filter": {
|
||||
"IN": { "value.person.org": [ "Dev Ops", "Hardware" ] }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,34 +1,32 @@
|
|||
{
|
||||
"query": {
|
||||
"filter": {
|
||||
"OR": [
|
||||
{
|
||||
"EQ": { "value.person.org": "Dev Ops" }
|
||||
},
|
||||
{
|
||||
"AND": [
|
||||
{
|
||||
"EQ": { "value.person.org": "Finance" }
|
||||
},
|
||||
{
|
||||
"IN": { "value.state": [ "CA", "WA" ] }
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"sort": [
|
||||
"filter": {
|
||||
"OR": [
|
||||
{
|
||||
"key": "value.state",
|
||||
"order": "DESC"
|
||||
"EQ": { "value.person.org": "Dev Ops" }
|
||||
},
|
||||
{
|
||||
"key": "value.person.id"
|
||||
"AND": [
|
||||
{
|
||||
"EQ": { "value.person.org": "Finance" }
|
||||
},
|
||||
{
|
||||
"IN": { "value.state": [ "CA", "WA" ] }
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"pagination": {
|
||||
"limit": 3,
|
||||
"token": "3"
|
||||
]
|
||||
},
|
||||
"sort": [
|
||||
{
|
||||
"key": "value.state",
|
||||
"order": "DESC"
|
||||
},
|
||||
{
|
||||
"key": "value.person.id"
|
||||
}
|
||||
],
|
||||
"page": {
|
||||
"limit": 3,
|
||||
"token": "3"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,33 +1,31 @@
|
|||
{
|
||||
"query": {
|
||||
"filter": {
|
||||
"OR": [
|
||||
{
|
||||
"EQ": { "value.person.org": "Dev Ops" }
|
||||
},
|
||||
{
|
||||
"AND": [
|
||||
{
|
||||
"EQ": { "value.person.org": "Finance" }
|
||||
},
|
||||
{
|
||||
"IN": { "value.state": [ "CA", "WA" ] }
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"sort": [
|
||||
"filter": {
|
||||
"OR": [
|
||||
{
|
||||
"key": "value.state",
|
||||
"order": "DESC"
|
||||
"EQ": { "value.person.org": "Dev Ops" }
|
||||
},
|
||||
{
|
||||
"key": "value.person.id"
|
||||
"AND": [
|
||||
{
|
||||
"EQ": { "value.person.org": "Finance" }
|
||||
},
|
||||
{
|
||||
"IN": { "value.state": [ "CA", "WA" ] }
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"pagination": {
|
||||
"limit": 3
|
||||
]
|
||||
},
|
||||
"sort": [
|
||||
{
|
||||
"key": "value.state",
|
||||
"order": "DESC"
|
||||
},
|
||||
{
|
||||
"key": "value.person.id"
|
||||
}
|
||||
],
|
||||
"page": {
|
||||
"limit": 3
|
||||
}
|
||||
}
|
||||
|
|
|
@ -333,36 +333,34 @@ An array of JSON-encoded values
|
|||
curl http://localhost:3500/v1.0-alpha1/state/myStore/query \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"query": {
|
||||
"filter": {
|
||||
"OR": [
|
||||
{
|
||||
"EQ": { "value.person.org": "Dev Ops" }
|
||||
},
|
||||
{
|
||||
"AND": [
|
||||
{
|
||||
"EQ": { "value.person.org": "Finance" }
|
||||
},
|
||||
{
|
||||
"IN": { "value.state": [ "CA", "WA" ] }
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"sort": [
|
||||
"filter": {
|
||||
"OR": [
|
||||
{
|
||||
"key": "value.state",
|
||||
"order": "DESC"
|
||||
"EQ": { "value.person.org": "Dev Ops" }
|
||||
},
|
||||
{
|
||||
"key": "value.person.id"
|
||||
"AND": [
|
||||
{
|
||||
"EQ": { "value.person.org": "Finance" }
|
||||
},
|
||||
{
|
||||
"IN": { "value.state": [ "CA", "WA" ] }
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"pagination": {
|
||||
"limit": 3
|
||||
]
|
||||
},
|
||||
"sort": [
|
||||
{
|
||||
"key": "value.state",
|
||||
"order": "DESC"
|
||||
},
|
||||
{
|
||||
"key": "value.person.id"
|
||||
}
|
||||
],
|
||||
"page": {
|
||||
"limit": 3
|
||||
}
|
||||
}'
|
||||
```
|
||||
|
|
Loading…
Reference in New Issue