# Data Read

{% hint style="info" %}
**Block Information**

Available in: Page Flow and Cloud Flow

Toolbox Category: Data - Read

Block Type: [Regular](https://docs.zingy.ai/app-editor/block-anatomy#regular-block)
{% endhint %}

**`Data Read`** is a [regular block](https://docs.zingy.ai/app-editor/block-anatomy#regular-block) that initiates a reading of [records](https://docs.zingy.ai/data/database-tables#table-records) from a [database table](https://docs.zingy.ai/app-editor/data/database-tables).

<div align="left"><figure><img src="https://3401585094-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmnBepgycwgisXr9ya1N4%2Fuploads%2FTp7qazOAPAnXeaaqn16b%2Fimage.png?alt=media&#x26;token=32e862e4-2e91-4dbb-bd7d-053e3c86adbe" alt="" width="197"><figcaption><p>Data Read block</p></figcaption></figure></div>

The block consists of the following (from top to bottom):

* *Table:* [Value Parameter](https://docs.zingy.ai/app-editor/block-anatomy#value-parameters) that accepts a [*text*](https://docs.zingy.ai/app-editor/page-flow/references/value-types) value representing the name of the [Database Table](https://docs.zingy.ai/app-editor/data/database-tables) .
* *Query:* Optional [Value Parameter](https://docs.zingy.ai/app-editor/block-anatomy#value-parameters) that accepts a [*text*](https://docs.zingy.ai/app-editor/page-flow/references/value-types) value representing the name of the [Database Query](https://docs.zingy.ai/app-editor/data/database-queries) . If this is blank, the database is read without any search criteria and sorting rules.&#x20;
* *Dataset Name:* [Value Parameter](https://docs.zingy.ai/app-editor/block-anatomy#value-parameters) that accepts a [*text*](https://docs.zingy.ai/app-editor/page-flow/references/value-types) value representing the name of the dataset. This can be any [*text*](https://docs.zingy.ai/app-editor/page-flow/references/value-types) value and can later be used to track the completion of the read.
* *Per Page*: [Value Parameter](https://docs.zingy.ai/app-editor/block-anatomy#value-parameters) that accepts a [numeric](https://docs.zingy.ai/app-editor/page-flow/references/value-types) value containing the number of [records](https://docs.zingy.ai/data/database-tables#table-records) to be read. This number is preserved for subsequent usage of the [Data Read Next](https://docs.zingy.ai/app-editor/page-flow/toolbox-blocks/data-read-next) and [Data Read Previous](https://docs.zingy.ai/app-editor/page-flow/toolbox-blocks/data-read-previous) blocks when the same *Dataset Name* is used.
* *Input Criteria*: Optional [Value Parameter](https://docs.zingy.ai/app-editor/block-anatomy#value-parameters) that accepts an [object](https://docs.zingy.ai/app-editor/page-flow/references/value-types) value. This is required only if a database query is selected for the *Query* parameter above. If the query contains search criteria parameters, the pre-attached Object block automatically gets populated.

{% hint style="success" %}
**NOTE**:&#x20;

* This block initiates the database read, which will occur in the background. To track the status and to take an action upon completion of the read, use the [Data Status](https://docs.zingy.ai/app-editor/page-flow/toolbox-blocks/data-status) block.&#x20;
* To access the records after a successful read, see [Data Record Count](https://docs.zingy.ai/app-editor/page-flow/toolbox-blocks/data-record-count), [Data Record Loop](https://docs.zingy.ai/app-editor/page-flow/toolbox-blocks/data-record-loop), [Data Record at Index](https://docs.zingy.ai/app-editor/page-flow/toolbox-blocks/data-record-at-index) blocks.
  {% endhint %}

***

## Usage Examples

{% hint style="info" %}
**NOTE: Please refer to the prerequisite information shown** [**here**](https://docs.zingy.ai/app-editor/page-flow/references/prerequisite-for-data-examples) **before seeing the example.**&#x20;
{% endhint %}

The image below shows our first example.

<div align="left"><figure><img src="https://3401585094-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmnBepgycwgisXr9ya1N4%2Fuploads%2FJE1eULGZSnYzeBQ5OJS5%2Fimage.png?alt=media&#x26;token=d1ca9449-6fca-4277-b8f0-adbd8599fd88" alt="" width="527"><figcaption><p>Data Read Example 1</p></figcaption></figure></div>

In the above example, we initiate a database read for the *Customers* table which we have discussed [here](https://docs.zingy.ai/app-editor/page-flow/references/prerequisite-for-data-examples). The Data Status block is used to track the status, and here we use the same *Customers* table and the dataset name of *ds1*. Upon success, we invoke the function *Usage Example*. We will look at some sample implementations for the *Usage Example* function.

<div><figure><img src="https://3401585094-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmnBepgycwgisXr9ya1N4%2Fuploads%2FbhVylr45xw4tTMr256nC%2Fimage.png?alt=media&#x26;token=d627ed68-c10a-41a2-b2ce-78c50e0da726" alt=""><figcaption><p>(1) Show the number of records read using the Data Read Count block</p></figcaption></figure> <figure><img src="https://3401585094-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmnBepgycwgisXr9ya1N4%2Fuploads%2FhbVk7uKgAPsdfStkgcjo%2Fimage.png?alt=media&#x26;token=47ccd404-e3cc-463e-bd59-17213fefbcc7" alt=""><figcaption><p>(2) Use the Data Record Loop block to iterate over all the records</p></figcaption></figure></div>

The above sample implementations are discussed in more detail [here](https://docs.zingy.ai/app-editor/page-flow/data-record-count#usage-example) and [here](https://docs.zingy.ai/app-editor/page-flow/data-record-loop#usage-example).

Now let's take a look at another example, this time we will use the *NameMatch* query that is defined for the *Customers* table and is discussed [here](https://docs.zingy.ai/app-editor/references/prerequisite-for-data-examples#sample-queries).

<figure><img src="https://3401585094-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmnBepgycwgisXr9ya1N4%2Fuploads%2Fj9mLdtTBzvJjh1enjjGu%2Fimage.png?alt=media&#x26;token=f548180a-238a-461f-8847-bc6824414bdd" alt=""><figcaption><p>Data Read Example 2</p></figcaption></figure>

The optional *Input Criteria* parameter is attached to the Object block, which has one property *Input-1* with a value of *Smi*. Remember that the [*NameMatch* query](https://docs.zingy.ai/app-editor/references/prerequisite-for-data-examples#sample-queries) accepts one input parameter and will list records where either the *FirstName* or the *LastName* fields contains the given input.

Also note the sample records contained in the *Customers* database table provided [here](https://docs.zingy.ai/app-editor/references/prerequisite-for-data-examples#sample-records).

The result for the above example can be seen in the [browser's web console](https://developer.chrome.com/docs/devtools/console/), and a sample is shown below:

```log
[LOG(info) 08/30/2023 17:29:52.179] Name: Jane Smith
[LOG(info) 08/30/2023 17:29:52.181] Name: John Smith
```

Since the *Input-1* parameter was set to the value *Smi*, the database read resulted in the records of Jane Smith and John Smith being shown.
