Skip to main content

Syntax

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.createRecords(object);

Basic usage​

The following example inserts two new product records and includes a validation rule to ensure the name field is provided for every row.

TypeScript
const res = await manta.createRecords({
table: 'products',
data: [
{ product_id: 'P-A1', name: 'Laptop' },
{ product_id: 'P-B2', name: 'Phone' }
],
options: {
validationRule: { name: { required: true } }
}
});

Global defaults​

You can set default options for all createRecords calls using manta.setDefaultOptions. These defaults are merged into every call, but any options specified in the call itself will override the global settings.

TypeScript
// Configure defaults that are merged into each call (per-call options override):
manta.setDefaultOptions({ dryRun: true, chunkSize: 10000 });

// The 'dryRun: false' here will override the global 'dryRun: true'
await manta.createRecords({
table: "users",
data: [{ email: "real@example.com" }],
options: { dryRun: false },
});
💡Chunk size limit

The chunkSize parameter has a maximum limit of 10,000 records per batch.

😉Use dry runs for testing

Enable the dryRun to test validation rules and preview which records would be created or updated without modifying your data.

Response​

On success, the API returns a standard MantaResponse object that includes counts of records processed. If dryRun is set to true, the response will also include preview information.

JSON
{
"message": "Successfully processed 2 records",
"status": true,
"data": {
"created": 2,
"updated": 0,
"failed": 0,
"processedCount": 2,
"totalCount": 2
}
}