Skip to content

Commit 9be5738

Browse files
committed
..
1 parent 95d40aa commit 9be5738

File tree

1 file changed

+32
-36
lines changed

1 file changed

+32
-36
lines changed

website/docs/packages/tutorial/query-module.md

Lines changed: 32 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@ You'll create a reusable query module using product inventory data and display t
3333

3434
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.
3535

36+
3637
<div style={{ position: "relative", paddingBottom: "calc(50.52% + 41px)", height: 0, width: "100%" }}>
3738
<iframe
38-
src="https://demo.arcade.software/Zm91UIkEM0nSlq2MGzOQ?embed"
39+
src="https://demo.arcade.software/yPMGvRmB4KZ03CcKZZtv?embed"
3940
frameBorder="0"
4041
loading="lazy"
4142
webkitAllowFullScreen
@@ -50,48 +51,41 @@ A reusable query module is a query that can be used across multiple applications
5051

5152

5253

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**.
5655

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.
5856

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`.
6058

6159
<dd>
6260

63-
* **Connection mode:** `READ_WRITE`
64-
* **Host address:** `aws-0-us-east-1.pooler.supabase.com`
65-
* **Port:** `5432`
66-
* **Database name:** `postgres`
67-
* **Username:** `postgres.hazwlkzitjmrmqbpkqch`
68-
* **Password:** `w9uDFMhmMzOOvPbv`
61+
- **Code Packages:** Contain reusable query and JS modules that can be shared across your workspace.
6962

63+
- **UI Packages:** Contain UI modules, bundling widgets, queries, and JavaScript logic into reusable units. See [UI Modules](/packages/tutorial/ui-module).
64+
7065
</dd>
7166

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.
7368

74-
6. Click **+ New Reusable Query** from the top-right corner of the datasource editor.
7569

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.
7971

72+
5. Rename the query to `GetUsers` and configure it with the following SQL:
8073

8174
<dd>
8275

8376
```sql
84-
SELECT * FROM public."product" LIMIT 5 OFFSET 4;
77+
SELECT * FROM public."users" LIMIT 10 OFFSET 4;
8578
```
8679

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.
8883

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.
9185

9286
</dd>
9387

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.
9589

9690
<dd>
9791

@@ -101,26 +95,26 @@ Create two inputs:
10195
* `limit`, with a default value of `5`.
10296
* `offset`, with a default value of `4`.
10397

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.
10599

106100
</dd>
107101

108102

109-
10. Update the query by using `inputs` property for dynamic adjustments:
103+
7. Update the query by using `inputs` property for dynamic adjustments:
110104

111105
<dd>
112106

113107

114108
```sql
115-
SELECT * FROM public."product" LIMIT {{inputs.limit}} OFFSET {{inputs.offset}};
109+
SELECT * FROM public."users" LIMIT {{inputs.limit}} OFFSET {{inputs.offset}};
116110
```
117111

118112
</dd>
119113

120-
11. **Run** the query to ensure it retrieves the data correctly.
114+
8. **Run** the query to ensure it retrieves the data correctly.
121115

122116

123-
12. **Publish** the query module from top-right corner. This allows the changes to reflect on the app side.
117+
9. **Publish** the query module from top-right corner. This allows the changes to reflect on the app side.
124118

125119
<dd>
126120

@@ -135,10 +129,9 @@ If the package is git-connected, you also need to release a new version for the
135129
Great job on creating a query module! Now, let's see how you can reuse it in different apps.
136130

137131

138-
139132
<div style={{ position: "relative", paddingBottom: "calc(50.52% + 41px)", height: 0, width: "100%" }}>
140133
<iframe
141-
src="https://demo.arcade.software/t77RIouwmGGXyyuUN8j8?embed"
134+
src="https://demo.arcade.software/M6Wcxy6NVNFg51KFihM2?embed"
142135
frameBorder="0"
143136
loading="lazy"
144137
webkitAllowFullScreen
@@ -151,18 +144,21 @@ Great job on creating a query module! Now, let's see how you can reuse it in dif
151144
</div>
152145

153146

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.
155150

156-
2. From the **Queries** Tab, click **+ New query / API**.
151+
<dd>
157152

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
159154

160-
4. **Run** the query module.
155+
</dd>
161156

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.
163158

159+
5. To display the data, drag a **Table** widget onto the canvas, click **Connect Data**, and select the `GetUsers1` query module instance.
164160

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.
166162

167163
<dd>
168164

@@ -179,7 +175,7 @@ This configuration dynamically sets the limit and offset based on the values fro
179175
7. Enable the **Server-side pagination** property in the Table.
180176

181177

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.
183179

184180
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.
185181

0 commit comments

Comments
 (0)