# Access Database from Page

Pages created using **Page Designer** can access data through structured mechanisms that align with ONEWEB’s **Data & Content Management** model.\
Unlike Smart Forms—which are entity‑centric—Pages provide more flexibility for **custom UI layouts, dashboards, and interactive data views**.

ONEWEB supports **two primary approaches** for accessing databases from Pages:

* **Through Microflow** (recommended, server‑side)
* **Through Local Database** (mobile applications only)

***

### Access Database from Page Using Microflow

**Microflow‑based data access** is the standard and recommended approach for Pages that need to interact with server‑side data.

***

#### How Microflow Enables Data Access

Microflow provides a **Database Node** that allows Pages to interact with databases by configuring:

* Connection type
* SQL command type (`SELECT`, `INSERT`, `UPDATE`, `DELETE`)
* Input and output data mapping

This approach ensures that:

* Database logic is centralized
* Business rules and validations are enforced
* Pages do not access databases directly

<figure><img src="https://2015371994-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMpDjHWFRUtZ5nJcSfVXd%2Fuploads%2FtMcnTllH5HEMCGOza0GE%2Fimage.png?alt=media&#x26;token=49a185ca-d569-4c2f-90fa-9d32c2726cf5" alt=""><figcaption></figcaption></figure>

***

#### Integrate Page with Microflow

Once the Microflow is prepared:

1. Integrate the Page with the Microflow
2. Bind Page actions or elements to trigger the Microflow
3. Consume the returned dataset in the Page UI

> For detailed integration steps, see:\
> **Page Integration with Microflow**\
> <https://docs.oneweb.tech/oneweb/design-and-develop-oneweb-apps/design-and-develop-ux-ui/ux-ui-integration-with-process-micro-flow-external-ui/page-integration-with-microflow>

After integration, the Page can **read or manipulate database data exclusively through Microflow**.

***

#### When to Use Microflow

Use Microflow‑based access when:

* Data comes from the central database
* Business logic must be enforced
* Multiple pages reuse the same data logic
* Security, auditability, and consistency are required

***

### Access Database from Page Using Local Database (Mobile Only)

ONEWEB also supports **Local Database access**, which is intended **only for mobile applications**.\
This approach is used to support **offline access, caching, or local data storage**.

***

#### Step 1: Prepare Local Database

1. Create a table in the Local Database
2. Populate or synchronize data from the server if required

> For details, refer to:\
> **Local Database (Local Storage in Page)**\
> <https://docs.oneweb.tech/oneweb/design-and-develop-oneweb-apps/design-and-develop-ux-ui/ux-ui-components/pages/page-features/local-storage-in-page>

<figure><img src="https://2015371994-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMpDjHWFRUtZ5nJcSfVXd%2Fuploads%2FtPQSY9ARhIqWQInKvsPz%2Fimage.png?alt=media&#x26;token=db8027db-778f-4208-8c4c-0aa6fea3947b" alt=""><figcaption></figcaption></figure>

***

#### Step 2: Configure Page‑Level Data Query

1. Open the target Page in Page Designer
2. Select **PageContent** level
3. Configure an action to query data from the Local Database

<figure><img src="https://2015371994-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMpDjHWFRUtZ5nJcSfVXd%2Fuploads%2FobQkjWbpl8DuBrZTj3t8%2Fimage.png?alt=media&#x26;token=f3cf1314-20e3-4025-bbb9-391a3346b764" alt=""><figcaption></figcaption></figure>

***

#### Step 3: Bind Data to Page Elements

**Parent Element**

1. Select the **parent UI element**
2. Open **Connect to Data**
3. Set:
   * Datasource: **Database**
   * Table: Local database table

<figure><img src="https://2015371994-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMpDjHWFRUtZ5nJcSfVXd%2Fuploads%2Fxz46eMCMeGHcEM9RpIXL%2Fimage.png?alt=media&#x26;token=277a6cfd-f8b1-4411-8d42-01ac07586af9" alt=""><figcaption></figcaption></figure>

***

**Child Elements**

1. Select the **child UI element**
2. Open **Connect to Data**
3. Configure:
   * Datasource: **Database**
   * Enable **Data from a parent**
   * Select the appropriate **Data field**

<figure><img src="https://2015371994-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMpDjHWFRUtZ5nJcSfVXd%2Fuploads%2F0w7ieCi6W5oYwpEQEP4v%2Fimage.png?alt=media&#x26;token=bc54c14c-2c8d-4a66-973a-065fa987d4e4" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2015371994-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMpDjHWFRUtZ5nJcSfVXd%2Fuploads%2FPajohBaqBZdBpG053Ynr%2Fimage.png?alt=media&#x26;token=7e85f08e-e87f-423d-bf0b-19e9db8973da" alt=""><figcaption></figcaption></figure>

***

#### Step 4: Preview Result

Save the Page and click **Play Me** to preview the data rendered from the Local Database.

<figure><img src="https://2015371994-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMpDjHWFRUtZ5nJcSfVXd%2Fuploads%2FHJulvGHZCPTbZnTZJfA3%2Fimage.png?alt=media&#x26;token=18145348-f2c8-449f-a5e6-ba573634a591" alt=""><figcaption></figcaption></figure>

***

### Choosing the Right Approach

| Approach           | Use Case                                       |
| ------------------ | ---------------------------------------------- |
| **Microflow**      | Server‑side data, business logic, shared data  |
| **Local Database** | Mobile apps, offline data, performance caching |

***

### Summary

**Pages in ONEWEB access databases through structured and governed mechanisms**, ensuring consistency with **Data & Content Management** principles.

By using **Microflows** or **Local Databases**, applications can:

* Avoid direct database access from the UI
* Enforce business rules and data governance
* Support both online and offline mobility scenarios
* Scale cleanly across environments and devices

This layered approach ensures that data accessed from Pages remains **secure, maintainable, and aligned with application design**.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.onewebstack.com/oneweb-platform-th/building-apps/data-and-content-management/database-access-management/data-access-from-ux-ui/access-database-from-page.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
