> For the complete documentation index, see [llms.txt](https://docs.rierino.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.rierino.com/devops/api-event-and-process-flows/configuring-saga-steps/event-step/core-actions/query-data.md).

# Query Data

These actions provide ability to generate and execute system specific queries on a query manager on demand, from simple select statements to complex requests.

## Query Data Actions

`GetQuery` supports [Event Step](https://docs.rierino.com/devops/api-event-and-process-flows/configuring-saga-steps/event-step.md).

### GetQuery

Executes and returns results for a single query from a specific query manager. Event metadata fields applicable for this action are as follows:

{% tabs %}
{% tab title="Table" %}

| Field          | Definition                                                   | Example    | Default |
| -------------- | ------------------------------------------------------------ | ---------- | ------- |
| Domain         | Name of the query manager to read data from                  | product    | -       |
| Input Element  | Json path for the input in event payload for query variables | parameters | -       |
| Output Element | Json path for the output in response event payload           | $.list     | -       |
| {% endtab %}   |                                                              |            |         |

{% tab title="JSON Schema" %}

```json
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "Query Data GetQuery action eventMeta fields",
  "type": "object",
  "properties": {
    "eventMeta": {
      "type": "object",
      "properties": {
        "domain": {
          "type": "string",
          "definition": "Name of the query manager to read data from",
          "example": "product"
        },
        "inputElement": {
          "type": "string",
          "definition": "Json path for the input in event payload for query variables",
          "example": "parameters"
        },
        "outputElement": {
          "type": "string",
          "definition": "Json path for the output in response event payload",
          "example": "$.list"
        }
      }
    }
  }
}
```

{% endtab %}
{% endtabs %}

With event metadata parameters as:

{% tabs %}
{% tab title="Table" %}

| Parameter           | Definition                                                          | Example                                               | Default |
| ------------------- | ------------------------------------------------------------------- | ----------------------------------------------------- | ------- |
| Output Pattern      | JMESPath pattern to apply on data output, before returning response | {id:id, name:data.name, description:data.description} | -       |
| Output List Pattern | JMESPath pattern applied to the full result list before returning   | \[?data.status=='A']                                  | -       |
| Query ID            | Id of the query to execute                                          | product\_search\_0001                                 | -       |
| Query Name          | Name of the query to execute                                        | Product Search                                        | -       |
| Query Json          | Full Json representation of query to execute                        | -                                                     | -       |
| First               | Whether to return first record only from results                    | true                                                  | false   |
| Sort Path           | Json path in query results to be used for sorting                   | product.id                                            | -       |
| Sorter Path         | Json path in request event payload to be used for sorting           | productids                                            | -       |
| {% endtab %}        |                                                                     |                                                       |         |

{% tab title="JSON Schema" %}

```json
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "Query Data GetQuery action eventMeta.parameters",
  "type": "object",
  "properties": {
    "eventMeta": {
      "type": "object",
      "properties": {
        "parameters": {
          "type": "object",
          "properties": {
            "outputPattern": {
              "type": "string",
              "definition": "JMESPath pattern to apply on data output, before returning response",
              "example": "{id:id, name:data.name, description:data.description}"
            },
            "outputListPattern": {
              "type": "string",
              "definition": "JMESPath pattern applied to the full result list before returning",
              "example": "[?data.status=='A']"
            },
            "queryId": {
              "type": "string",
              "definition": "Id of the query to execute",
              "example": "product_search_0001"
            },
            "queryName": {
              "type": "string",
              "definition": "Name of the query to execute",
              "example": "Product Search"
            },
            "queryJson": {
              "type": "object",
              "definition": "Full Json representation of query to execute"
            },
            "first": {
              "type": "boolean",
              "definition": "Whether to return first record only from results",
              "default": false
            },
            "sortPath": {
              "type": "string",
              "definition": "Json path in query results to be used for sorting",
              "example": "product.id"
            },
            "sorterPath": {
              "type": "string",
              "definition": "Json path in request event payload to be used for sorting",
              "example": "productids"
            }
          }
        }
      }
    }
  }
}
```

{% endtab %}
{% endtabs %}

<details>

<summary>Example</summary>

Input

```json
{
    "parameters": {
        "search": "test"
    }
}
```

Event Metadata

![](https://1659095931-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcnDk3J1AzTgg2NFrGPlh%2Fuploads%2FjrU0seVBkH3WSbsxFtQ5%2Fimage.png?alt=media\&token=ebf139b6-d990-433b-9853-6291b38f48fe)

</details>

{% hint style="info" %}
sortPath and sorterPath parameters are used to allow sorting of results by an already prioritized list of ids (such as product ids sorted based on search releavence).
{% endhint %}

### ProduceQuery

Generates a query statement for a specific query manager, which is typically used by 3rd party systems in converting query objects into system specific requests. Event metadata fields applicable for this action are as follows:

{% tabs %}
{% tab title="Table" %}

| Field          | Definition                                                   | Example    | Default |
| -------------- | ------------------------------------------------------------ | ---------- | ------- |
| Domain         | Name of the query manager to produce statement for           | product    | -       |
| Input Element  | Json path for the input in event payload for query variables | parameters | -       |
| Output Element | Json path for the output in response event payload           | $.query    | -       |
| {% endtab %}   |                                                              |            |         |

{% tab title="JSON Schema" %}

```json
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "Query Data ProduceQuery action eventMeta fields",
  "type": "object",
  "properties": {
    "eventMeta": {
      "type": "object",
      "properties": {
        "domain": {
          "type": "string",
          "definition": "Name of the query manager to produce statement for",
          "example": "product"
        },
        "inputElement": {
          "type": "string",
          "definition": "Json path for the input in event payload for query variables",
          "example": "parameters"
        },
        "outputElement": {
          "type": "string",
          "definition": "Json path for the output in response event payload",
          "example": "$.query"
        }
      }
    }
  }
}
```

{% endtab %}
{% endtabs %}

With event metadata parameters as:

{% tabs %}
{% tab title="Table" %}

| Parameter    | Definition                                   | Example               | Default |
| ------------ | -------------------------------------------- | --------------------- | ------- |
| Query ID     | Id of the query to execute                   | product\_search\_0001 | -       |
| Query Name   | Name of the query to execute                 | Product Search        | -       |
| Query Json   | Full Json representation of query to execute | -                     | -       |
| {% endtab %} |                                              |                       |         |

{% tab title="JSON Schema" %}

```json
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "Query Data ProduceQuery action eventMeta.parameters",
  "type": "object",
  "properties": {
    "eventMeta": {
      "type": "object",
      "properties": {
        "parameters": {
          "type": "object",
          "properties": {
            "queryId": {
              "type": "string",
              "definition": "Id of the query to execute",
              "example": "product_search_0001"
            },
            "queryJson": {
              "type": "object",
              "definition": "Full Json representation of query to execute"
            },
            "queryName": {
              "type": "string",
              "definition": "Name of the query to execute",
              "example": "Product Search"
            }
          }
        }
      }
    }
  }
}
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
Produced statement is returned as a "query" field of the outputElement.
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.rierino.com/devops/api-event-and-process-flows/configuring-saga-steps/event-step/core-actions/query-data.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
