Skip to main content

Syntax

The updateRecords method modifies existing records in a table based on specified filters. It supports both native Manta tables and external PostgreSQL databases.

First, import the MantaClient from the library, see Getting Started:

💡Prerequisite

Before using this method, ensure that the target table is configured in Manta or that your external PostgreSQL database is connected in the MantaHQ dashboard.

This method accepts a single object as its parameter.

TypeScript
manta.updateRecords(object);

Basic usage​

Single condition-based update​

This example updates all records in a products table where the category_id is 'cat-1'. All matching records will be updated with the new name and price.

TypeScript
const result = await manta.updateRecords({
table: "products",
data: {
name: "Updated Product",
price: 99.99,
},
where: { category_id: "cat-1" },
});

Multiple condition-based update​

You can apply separate update payloads to specific records by providing arrays for both data and where. The SDK applies these updates sequentially.

TypeScript
const result = await manta.updateRecords({
table: "employees",
data: [
{ name: "Jane Doe", department: "Engineering" },
{ name: "John Smith", department: "Marketing" },
],
where: [{ user_id: "E01488" }, { user_id: "E04415" }],
});
💡Note

When using arrays for data and where, they must have the same length. Each data object updates the record matched by the corresponding where condition.

Response​

Success response​

The response includes counts of records processed and details about any nested updates.

JSON
{
"message": "Successfully processed 1 records",
"status": true,
"data": {
"created": 0,
"updated": 1,
"failed": 0,
"processedCount": 1,
"totalCount": 1,
"nested": []
}
}

Error response​

An error response will detail the validation failure, including the index of the row and the field that caused the error. Note that the status will be false (or the HTTP status code will be non-200).

JSON
{
"message": "Validation failed for one or more records",
"state": false,
"errors": [
{
"rowIndex": 0,
"field": "name",
"message": "Field 'name' must be at least 3 characters long"
}
],
"extras": [],
"statusCode": 400
}