Parameters
The createRecords() method object can contain the following properties:
| Parameter | Type | Required | Description |
|---|---|---|---|
table | string | Yes | The name of the target table to insert records into. |
data | Array<Record<string, any> & { validation?: Record<string, ValidationRule> }> | Yes | The array of records to insert. Each record can optionally contain its own validation rules. |
options | CreateRecordsOptions | No | Configuration flags that control the behaviour of the insertion, validation, and conflict resolution. |
Options
| Option | Type | Description |
|---|---|---|
dryRun | boolean | If true, the insertion is simulated. The API returns the wouldCreate or wouldUpdate counts without writing any data. |
validationRule | Record<string, ValidationRule> | A single global validation object that applies to all rows. Per-row validation rules can override this. |
continueOnError | boolean | If true, valid rows are processed and inserted, and the response returns detailed errors for the invalid rows. If false, the entire request fails on the first error. |
upsert | boolean | If true, MantaHQ attempts to update matching records instead of creating new ones; otherwise, conflicts are rejected. |
conflictKeys | string[] | An array of columns (fields) to check for conflicts (for example ['product_id', 'email']). |
conflictKeysLogic | 'and' | 'or' | Specifies whether all keys must match (and) or any key must match (or) to determine a conflict. |
chunkSize | number | The number of records to process in a single batch (for future use). |
condition | object | Only process rows that satisfy this condition (supports and/or and comparison operators). |
Validation rules
The validationRule object supports the following constraints:
- Presence and length:
required,minLength,maxLength. - Format:
format(e.g.,email,url,uuid,date,datetime,number,integer,boolean,string). - Custom checks:
regex,enum.
Supported condition operators
You can use the following friendly syntax operators within the condition object to build complex processing rules. These operators work for the main record condition and for filtering nested records.
| Operator | Meaning | Example |
|---|---|---|
equals | Equal | { status: { equals:'active' } } |
notEquals | Not equal | { status: { notEquals:'inactive' } } |
greaterThan | Greater than | { age:{ greaterThan:18 } } |
greaterOrEqual | Greater than or equals | { age:{ greaterOrEqual:18 } } |
lessThan | Less than | { price:{ lessThan:100 } } |
lessOrEqual | Less than or equals | { price:{ lessOrEqual:100 } } |
in | Value is present in the array | { country:{ in:['US','CA'] } } |
notIn | Value is not present in the array | { status:{ notIn:['banned','inactive'] } } |
and | All nested conditions must be true | { and:{ age:{>=18}, role:{equals:'admin'} } } |
or | At least one nested condition must be true | { or:{ role:{equals:'vip'}, status:{equals:'active'} } } |
Conditional creation
The condition object allows you to process a record only if it satisfies specific criteria. This example demonstrates combining and and or logic for precise control over record insertion.
- Manta data table
- PostgreSQL
TypeScript
await manta.createRecords({
table: "user",
data: [{ name: "Eve", age: 22, role: "admin", status: "vip" }],
options: {
condition: {
and: {
age: { greaterOrEqual: 18 },
or: { role: { equals: "admin" }, status: { equals: "vip" } },
},
},
},
});
TypeScript
const res = await manta.createRecords({
db: "analytics_pg", // Your unique connection name
table: "user",
data: [{ name: "Eve", age: 22, role: "admin", status: "vip" }],
options: {
condition: {
and: {
age: { greaterOrEqual: 18 },
or: { role: { equals: "admin" }, status: { equals: "vip" } },
},
},
},
});
💡Note
In this example, the record is inserted only if the age is 18 or older AND the role is 'admin' OR the status is 'vip'.