# Query Library

## Features

The main function of the query \*\*\*\* library is to create and manage reusable queries:

* Writing queries based on data sources, with the ability to define **Inputs** variables.

<figure><img src="https://125370873-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FzdpN2Lz0hzXpnNScDzVt%2Fuploads%2Fu0nOLHGqlJXtewkcu5nL%2FConnectDbBuilderQuery.gif?alt=media&#x26;token=a8ac8df3-a47f-4128-bf04-b8b5655e98fb" alt=""><figcaption></figcaption></figure>

* Importing and triggering queries from query library in apps and modules.

<figure><img src="https://125370873-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FzdpN2Lz0hzXpnNScDzVt%2Fuploads%2Ft5OStxvuOxv4oNe0oQUa%2FExportImportDataQuery.gif?alt=media&#x26;token=e73bfce2-9986-422f-8ed1-60fba3e48c56" alt=""><figcaption></figcaption></figure>

### Input parameters

There are cases where you want to pass dynamic parameters to a query. Appizap supports that by introducing input configuration of a query.

Click **Add** in the **Inputs** tab in the right pane to add input parameters. Reference them using `{{}}` in the query, then you can input test values to test execution of the query.

<figure><img src="https://125370873-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FzdpN2Lz0hzXpnNScDzVt%2Fuploads%2FbUjO8mVRMRiOOZjP1Hph%2FDataQueryInputParam.gif?alt=media&#x26;token=cb83d45d-d755-4eef-b6b7-713077928f5e" alt=""><figcaption></figcaption></figure>

{% hint style="warning" %}
You can only reference variables instead of writing JavaScript code in `{{}}`.
{% endhint %}

To edit the name and description of the input variables, click `...` and select **Edit** or directly click the title of the variable.

<figure><img src="https://125370873-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FzdpN2Lz0hzXpnNScDzVt%2Fuploads%2FioDSBsBcjJ2CxdNRGurf%2Fimage.png?alt=media&#x26;token=1056e021-b9cd-4b6e-a05c-b66ad22cd8c1" alt=""><figcaption></figcaption></figure>

## Version management

Queries may be updated on demand. You can make an adjustment to a query to a newer version and at the same time maintain the older version. Such version management is achievable in query library. Click `···` in the top right corner to publish different versions of queries, and you can view and restore history versions.

<figure><img src="https://125370873-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FzdpN2Lz0hzXpnNScDzVt%2Fuploads%2FczDsgpAMAFv7AZSPhOKd%2Fimage.png?alt=media&#x26;token=dea76337-6225-470d-a663-c30370e601fe" alt=""><figcaption></figcaption></figure>

### Publish

When you finish writing a version of the query, you can publish it. Click `···` > **Publish**. Use [semantic versioning](https://semver.org/) (also known as SemVer) to name your version.

<figure><img src="https://125370873-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FzdpN2Lz0hzXpnNScDzVt%2Fuploads%2FmwEiCCj49WCPJR7z4au7%2Fimage.png?alt=media&#x26;token=790b62e2-05d9-4080-aeee-ca467fdaa066" alt=""><figcaption></figcaption></figure>

### History version

To view and restore the history versions, go to `···` > **History version**.

You can restore your current draft to a history version by selecting the target version from the history version list and clicking **Restore this version**. Click **Exit** to return to edit mode.

<figure><img src="https://125370873-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FzdpN2Lz0hzXpnNScDzVt%2Fuploads%2FWsOJ71QACh8lceDzjwzW%2Fimage.png?alt=media&#x26;token=47c4393c-4022-4b0e-bfba-b7c3075693d0" alt=""><figcaption></figcaption></figure>

<figure><img src="https://github.com/nighthack/Appizap-Docs/blob/main/.gitbook/assets/query%20library%2013.png" alt=""><figcaption></figcaption></figure>

## Permissions

Workspace **Admin** and members of **Developers** group have access to the **Query Library** and have read and write permissions to all queries in the library.
