Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Modules #2085

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
Empty file.
Empty file.
118 changes: 118 additions & 0 deletions website/docs/packages/how-to-guides/create-query-module.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
---
title: Reuse queries
hide_title: true
---

<!-- vale off -->

<div className="tag-wrapper">
<h1>Reuse queries</h1>

<Tags
tags={[
{ name: "Business", link: "https://www.appsmith.com/pricing", additionalClass: "business" }
]}
/>

</div>

<!-- vale on -->

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.


<div style={{ position: "relative", paddingBottom: "calc(50.520833333333336% + 41px)", height: "0", width: "100%" }}>
<iframe src="https://demo.arcade.software/9SAjlISVyEOMSp1OUgYv?embed" frameborder="0" loading="lazy" webkitallowfullscreen mozallowfullscreen allowfullscreen style={{ position: "absolute", top: "0", left: "0", width: "100%", height: "100%", colorScheme: "light" }} title="Appsmith | Connect Data">
</iframe>
</div>

1. **Create a new package** by clicking on the top-right corner of your workspace.

2. Click **New Module** > **Query Module**, and select or create your datasource.

3. Click **Create Reusable Query** either from the datasource editor or the entity explorer.

4. Configure and Run the query.

5. 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:


<div style={{ position: "relative", paddingBottom: "calc(50.520833333333336% + 41px)", height: "0", width: "100%" }}>
<iframe src="https://demo.arcade.software/jGJZ8QTEqd4s2FGrIzCg?embed" frameborder="0" loading="lazy" webkitallowfullscreen mozallowfullscreen allowfullscreen style={{ position: "absolute", top: "0", left: "0", width: "100%", height: "100%", colorScheme: "light" }} title="Appsmith | Connect Data">
</iframe>
</div>



1. Open the **Package** and select the query module you want to configure.

2. 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 `{{}}`.

3. Configure the query by using `{{inputs.input_name_}}` for dynamic adjustments.

<dd>

_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:

Check warning on line 66 in website/docs/packages/how-to-guides/create-query-module.md

View workflow job for this annotation

GitHub Actions / vale

[vale] website/docs/packages/how-to-guides/create-query-module.md#L66

[Google.Colons] ': I' should be in lowercase.
Raw output
{"message": "[Google.Colons] ': I' should be in lowercase.", "location": {"path": "website/docs/packages/how-to-guides/create-query-module.md", "range": {"start": {"line": 66, "column": 10}}}, "severity": "WARNING"}



```sql
SELECT * FROM public."users" OFFSET {{inputs.offset}} LIMIT {{inputs.limit}};
```

</dd>

3. 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:



<div style={{ position: "relative", paddingBottom: "calc(50.520833333333336% + 41px)", height: "0", width: "100%" }}>
<iframe src="https://demo.arcade.software/UnflBQTrpoT9dMNNRz45?embed" frameborder="0" loading="lazy" webkitallowfullscreen mozallowfullscreen allowfullscreen style={{ position: "absolute", top: "0", left: "0", width: "100%", height: "100%", colorScheme: "light" }} title="Appsmith | Connect Data">
</iframe>
</div>


1. Open your App from the homepage and ensure that both the app and modules share the same workspace.

2. In the entity explorer, select the query module to view inputs, default values, and query settings.

3. To display query data, drop a Table widget and connect it to the **Query module**.

4. To update the query input values dynamically, use mustache binding `{{}}` to bind data.

<dd>

*Example*: If you want to pass the Table `pageSize` and `pageOffset` to the query module, update the input values to:

Check warning on line 101 in website/docs/packages/how-to-guides/create-query-module.md

View workflow job for this annotation

GitHub Actions / vale

[vale] website/docs/packages/how-to-guides/create-query-module.md#L101

[Google.Colons] ': I' should be in lowercase.
Raw output
{"message": "[Google.Colons] ': I' should be in lowercase.", "location": {"path": "website/docs/packages/how-to-guides/create-query-module.md", "range": {"start": {"line": 101, "column": 10}}}, "severity": "WARNING"}

```js
//limit input
{{Table1.pageSize}}

//offset input
{{Table1.pageOffset}}
```


</dd>

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

Empty file.
32 changes: 32 additions & 0 deletions website/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,38 @@ const sidebars = {
]
}, //CODE end

//module start
{
type: 'category',
collapsed: false,
label: 'Modules',
items: [
'packages/overview',
{
type: 'category',
collapsed: true,
label: 'How-To Guides',
link: { type: 'doc', id: 'packages/how-to-guides/README' },
items: [
'packages/how-to-guides/create-query-module',
'packages/how-to-guides/create-js-module'
]
},
{
type: 'category',
collapsed: true,
label: 'Concepts',
link: {
type: 'doc',
id: 'packages/concepts/README',
},
items: [

],
},
]
}, //module end

{
//Advanced Concepts Start
type: 'category',
Expand Down
Loading