Supista
Contact Us
documentation
Supista ERP
Parameters
API Operations
Read Operation

Read Operation

The readOp function is used to query records from a PostgreSQL table.

It returns both the total count of matching records and the list of rows.


Usage

const rowsData = await readOp(tableName, payload);

Parameters

tableName (Required)

The name of the PostgreSQL table to query data from.

payload (Required)

A modified userData object used for the Read API request.

To query a related table, the payload must also include:

  • __d3__parentId
  • __d3__relationId

Payload Structure

{
  __d3__filterdata: {
    where: {
      // filtering conditions
    }
  }
}

__d3__filterdata.where defines the filtering conditions for the query.


Return Value

Returns the result of Sequelize dataModel.findAndCountAll().

Sample Output

{
  count: 1,
  rows: [
    {
      id: 1,
      columnName1: "columnValue1",
      columnName2: "columnValue2",
      columnName3: "columnValue3"
    }
  ]
}
  • count → Total number of matching records
  • rows → Array of matched row objects

Example Implementation

async function customizeERP(userData, apiOperations) {
 
  const tableName = "table_name";
  const { readOp } = apiOperations;
 
  return new Promise(async (resolve, reject) => {
 
    const payload = {
      __d3__filterdata: {
        where: {}
      }
    };
 
    const rowsData = await readOp(tableName, payload);
 
    if (rowsData?.count) {
      resolve({ result: rowsData });
    } else {
      resolve({
        result: {},
        popupMsg: {
          type: "error",
          message: "Could Not read data! Please try again later"
        }
      });
    }
 
  });
}

Example Input

{
  "__d3__filterdata": {
    "where": {}
  }
}

Example Output

{
  "response": {
    "__d3__result": {
      "result": {
        "count": 2,
        "rows": [
          {
            "id": 1,
            "name": "Sample",
            "bio": "Sample",
            "create at": "2025-06-11T09:02:01.794Z",
            "__d3__createdBy": 575,
            "__d3__lastUpdatedBy": 575,
            "__d3__createdAt": "2025-05-21T16:28:50.975Z",
            "__d3__updatedAt": "2025-06-11T09:29:18.133Z",
            "__d3__deletedAt": null
          },
          {
            "id": 2,
            "name": "Sample_2",
            "bio": "Sample_2",
            "create at": "2025-06-11T09:02:01.794Z",
            "__d3__createdBy": 575,
            "__d3__lastUpdatedBy": 575,
            "__d3__createdAt": "2025-05-29T21:28:52.319Z",
            "__d3__updatedAt": "2025-05-29T21:28:52.319Z",
            "__d3__deletedAt": null
          }
        ]
      }
    },
    "__d3__error": false,
    "printConsole": []
  }
}
Transform Data into Decisions with Supista – Your Intelligent Data Partner
AI-Powered Operational Intelligence for Growing Businesses

Automate your operations. Orchestrate your workflows. Scale with confidence.

Book a free strategy session with our Automation Experts and discover how Supista’s AI-Composable ERP can transform your operations into a scalable and intelligent system.