Reuse queries
A reusable query module is a query that can be used across multiple applications within the same workspace. They prove beneficial for tasks like fetching details or creating filter queries, eliminating the need to create separate queries for each application.
Create query module
Module are reusable entities that can be created within Packages. Within packages, you can create multiple query and JS modules.
-
Create a new package by clicking on the top-right corner of your workspace.
-
Click New Module > Query Module, and select or create your datasource.
-
Click Create Reusable Query either from the datasource editor or the entity explorer.
-
Configure and Run the query.
-
Publish the query module.
Now, with these steps, you have successfully created a query module within your package. You can now reuse this query across multiple applications.
Pass parameters to module
To pass input values from any app to the query module for dynamic updates, follow these steps:
-
Open the Package and select the query module you want to configure.
-
In the query editor's property pane, create Inputs and add Default values. You can create multiple inputs and dynamically pass data to Default value using mustache binding
{{}}
. -
Configure the query by using
{{inputs.input_name_}}
for dynamic adjustments.
Example: If you want to create a pagination query using LIMIT and OFFSET, create two inputs named limit
and offset
, assign default values, and configure the query as follows:
SELECT * FROM public."users" OFFSET {{inputs.offset}} LIMIT {{inputs.limit}};
- Run and publish the query module.
Use query module
Once you've created a query module, follow these steps to access its data in any application:
-
Open your App from the homepage and ensure that both the app and modules share the same workspace.
-
In the entity explorer, select the query module to view inputs, default values, and query settings.
-
To display query data, drop a Table widget and connect it to the Query module.
-
To update the query input values dynamically, use mustache binding
{{}}
to bind data.
Example: If you want to pass the Table pageSize
and pageOffset
to the query module, update the input values to:
//limit input
{{Table1.pageSize}}
//offset input
{{Table1.pageOffset}}
- Set the Table widget's OnPageSizeChange and onPageChange event to trigger the query module.
Whenever there is a change in the Table page change, the query module is triggered, and the data is updated.