|
| 1 | +# Query library |
| 2 | + |
| 3 | +**Query Library** lets you store, reuse and share queries across your workspace. Create and run queries in query library, and call them from any Openblocks app. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +The main function of the query **** library is to create and manage reusable queries: |
| 8 | + |
| 9 | +* Writing queries based on data sources, with the ability to define **Inputs** variables.\ |
| 10 | + |
| 11 | + |
| 12 | + <figure><img src="../.gitbook/assets/query library 1.png" alt=""><figcaption></figcaption></figure> |
| 13 | +* Importing and triggering queries from query library in apps and modules.\ |
| 14 | + |
| 15 | + |
| 16 | + <figure><img src="../.gitbook/assets/query library 2.png" alt=""><figcaption></figcaption></figure> |
| 17 | +* Referencing different versions of queries.\ |
| 18 | + |
| 19 | + |
| 20 | + <figure><img src="../.gitbook/assets/query library 3.png" alt=""><figcaption></figcaption></figure> |
| 21 | + |
| 22 | +## Create a new query |
| 23 | + |
| 24 | +1. Click **+ New** and select a data source. |
| 25 | + |
| 26 | + <figure><img src="../.gitbook/assets/query library 4.png" alt=""><figcaption></figcaption></figure> |
| 27 | + |
| 28 | + |
| 29 | + |
| 30 | + <figure><img src="../.gitbook/assets/query library 5.png" alt=""><figcaption></figcaption></figure> |
| 31 | +2. Rename the query on demand. |
| 32 | +3. Write code and click ▶ **Run** to get results. The results will display in the bottom pane of the window. |
| 33 | + |
| 34 | + <figure><img src="../.gitbook/assets/query library 6.png" alt=""><figcaption></figcaption></figure> |
| 35 | + |
| 36 | +### Input parameters |
| 37 | + |
| 38 | +There are cases where you want to pass dynamic parameters to a query. Openblocks supports that by introducing input configuration of a query. |
| 39 | + |
| 40 | +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. |
| 41 | + |
| 42 | +<figure><img src="../.gitbook/assets/query library 7.png" alt=""><figcaption></figcaption></figure> |
| 43 | + |
| 44 | +{% hint style="warning" %} |
| 45 | +You can only reference variables instead of writing JavaScript code in `{{}}`. |
| 46 | +{% endhint %} |
| 47 | + |
| 48 | +To edit the name and description of the input variables, click `...` and select **Edit** or directly click the title of the variable. |
| 49 | + |
| 50 | +<figure><img src="../.gitbook/assets/query library 8.png" alt=""><figcaption></figcaption></figure> |
| 51 | + |
| 52 | +## Version management |
| 53 | + |
| 54 | +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. |
| 55 | + |
| 56 | +<figure><img src="../.gitbook/assets/query library 9.png" alt=""><figcaption></figcaption></figure> |
| 57 | + |
| 58 | +### Publish |
| 59 | + |
| 60 | +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. |
| 61 | + |
| 62 | +<figure><img src="../.gitbook/assets/query library 10.png" alt=""><figcaption></figcaption></figure> |
| 63 | + |
| 64 | +### History version |
| 65 | + |
| 66 | +To view and restore the history versions, go to `···` > **History version**. |
| 67 | + |
| 68 | +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. |
| 69 | + |
| 70 | +<figure><img src="../.gitbook/assets/query library 11.png" alt=""><figcaption></figcaption></figure> |
| 71 | + |
| 72 | +## Import a query |
| 73 | + |
| 74 | +1. In an app or module, Click **+ New** in the **Query editor** in the bottom pane, then select **Import from Query Library**. |
| 75 | + |
| 76 | + <figure><img src="../.gitbook/assets/query library 12.png" alt=""><figcaption></figcaption></figure> |
| 77 | +2. Select a query from the library from the dropdown list, choose your desired version and pass in corresponding input parameters. |
| 78 | + |
| 79 | + <figure><img src="../.gitbook/assets/query library 13.png" alt=""><figcaption></figcaption></figure> |
| 80 | + |
| 81 | + |
| 82 | + |
| 83 | + <figure><img src="../.gitbook/assets/query library 14.png" alt=""><figcaption></figcaption></figure> |
| 84 | +3. For other settings, see [query-basics.md](query-basics.md "mention"). |
| 85 | + |
| 86 | +## Permissions |
| 87 | + |
| 88 | +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. |
0 commit comments