You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: website/docs/packages/tutorial/query-module.md
+32-36Lines changed: 32 additions & 36 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -33,9 +33,10 @@ You'll create a reusable query module using product inventory data and display t
33
33
34
34
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.
@@ -50,48 +51,41 @@ A reusable query module is a query that can be used across multiple applications
50
51
51
52
52
53
53
-
1. Click **Create New** on the top-right corner of your workspace, and then select **New Package**.
54
-
55
-
2. Rename the package to `ProductUtils`.
54
+
1. Open your **Appsmith** workspace and click **Create New** on the top-right corner, then select **Package**.
56
55
57
-
3. Click the **New Module** button located at the center of the screen. Choose **Query Module** and proceed to create a **new datasource** by selecting PostgreSQL.
58
56
59
-
4. Enter the following details in the connection parameter fields. For this tutorial, we will use a product inventory database as an example to create queries and display data.
57
+
2. Select **Code Package**, and rename it to `UserUtils`.
-**Code Packages:** Contain reusable query and JS modules that can be shared across your workspace.
69
62
63
+
-**UI Packages:** Contain UI modules, bundling widgets, queries, and JavaScript logic into reusable units. See [UI Modules](/packages/tutorial/ui-module).
64
+
70
65
</dd>
71
66
72
-
5. Test and save the datasource.
67
+
3. In the Package UI, click on the **Queries** tab, then add a new datasource and select **Sample Users** Database.
73
68
74
-
6. Click **+ New Reusable Query** from the top-right corner of the datasource editor.
75
69
76
-
7. Rename the query module to `GetProducts`.
77
-
78
-
8. Configure the query to retrieve product details using the following SQL:
70
+
4. Once connected, click + New Reusable Query from the top-right corner of the datasource editor.
79
71
72
+
5. Rename the query to `GetUsers` and configure it with the following SQL:
80
73
81
74
<dd>
82
75
83
76
```sql
84
-
SELECT*FROM public."product"LIMIT5 OFFSET 4;
77
+
SELECT*FROM public."users"LIMIT10 OFFSET 4;
85
78
```
86
79
87
-
With this, you don't need to create multiple same queries for different pages or applications. You can reuse this same query module in various contexts, such as:
80
+
With this setup, you don't need to create separate queries each time you want to fetch user data. You can reuse this query module across multiple applications and widgets. For example:
81
+
82
+
- Display user information in a Table widget for user management pages.
88
83
89
-
- Displaying the entire inventory data in a Table widget.
90
-
- Displaying stock data in a chart widget, and more.
84
+
- Populate user statistics dynamically in a Chart widget to visualize user distribution.
91
85
92
86
</dd>
93
87
94
-
9. Click on the **+ Add Inputs**button from the right-side property pane. These inputs allow you to pass parameters from your application to query module, facilitating dynamic query adjustments based on user inputs or application requirements.
88
+
6. Click **+ Add Inputs**in the right-side pane. Inputs allow you to pass parameters dynamically from your application to the query module. If no dynamic values are provided, the query will use the default values set.
95
89
96
90
<dd>
97
91
@@ -101,26 +95,26 @@ Create two inputs:
101
95
*`limit`, with a default value of `5`.
102
96
*`offset`, with a default value of `4`.
103
97
104
-
If dynamic values are not passed, it takes the default value.
98
+
You can use these inputs to adjust queries based on user interactions, such as pagination or filtering within widgets.
105
99
106
100
</dd>
107
101
108
102
109
-
10. Update the query by using `inputs` property for dynamic adjustments:
103
+
7. Update the query by using `inputs` property for dynamic adjustments:
@@ -151,18 +144,21 @@ Great job on creating a query module! Now, let's see how you can reuse it in dif
151
144
</div>
152
145
153
146
154
-
1. Open your App or create a new one from the homepage and ensure that both the app and modules share the same workspace.
147
+
1. Open your existing App or create a new one from the homepage, ensuring both the App and modules are in the same workspace.
148
+
149
+
2. From the **Queries** tab, click **+ New query / API** and select the **GetUsers** query module from the `UserUtils` package.
155
150
156
-
2. From the **Queries** Tab, click **+ New query / API**.
151
+
<dd>
157
152
158
-
3. Select the `Add GetProducts`query module. You can add multiple instances of the same module and pass different parameters to each one.
153
+
When you add a query module into your app, it becomes a query module instance. You can add multiple instances of the same module and pass different parameters to each one
159
154
160
-
4.**Run** the query module.
155
+
</dd>
161
156
162
-
5. To display query data, drop a Table widget and connect it to the `GetProducts1`**Query module**.
157
+
4.**Run** the query module instance.
163
158
159
+
5. To display the data, drag a **Table** widget onto the canvas, click **Connect Data**, and select the `GetUsers1` query module instance.
164
160
165
-
6. From the **Queries** Tab, open the `GetProducts` query module and set the **inputs** to reference the properties of the Table widget.
161
+
6. From the **Queries** Tab, open the `GetUsers` query module and set the **inputs** to reference the properties of the Table widget.
166
162
167
163
<dd>
168
164
@@ -179,7 +175,7 @@ This configuration dynamically sets the limit and offset based on the values fro
179
175
7. Enable the **Server-side pagination** property in the Table.
180
176
181
177
182
-
8. Set the Table widget's **OnPageSizeChange** and **onPageChange** to execute the `GetProducts` query.
178
+
8. Set the Table widget's **OnPageSizeChange** and **onPageChange** to execute the `GetUsers` query.
183
179
184
180
With this, you have connected the query module to the Table widget and enabled server-side pagination, which allows you to dynamically fetch and display data based on the current page and page size.
0 commit comments