Validation
MantaHQ supports both global and per-row validation rules to ensure data integrity during updates. These rules prevent malformed data from reaching your internal Manta tables or external PostgreSQL databases.
Global validation
Global validation is used with a single object data payload. Define a validationRule object within options to apply constraints to all records matching the where condition.
- Manta data table
- PostgreSQL
TypeScript
await manta.updateRecords({
table: "products",
data: { name: "New Product", price: 99.99 },
where: { id: 1 },
options: {
validationRule: {
name: { required: true, minLength: 3 },
price: { required: true, greaterThan: 0 },
},
},
});
TypeScript
await manta.updateRecords({
db: "inventory_pg",
table: "products",
data: { name: "New Product", price: 99.99 },
where: { id: 1 },
options: {
validationRule: {
name: { required: true, minLength: 3 },
price: { required: true, greaterThan: 0 },
},
},
});
Per-row validation
When performing batch updates with an array of objects, define a validation object within each item. These rules apply specifically to that record and can override global rules.
- Manta data table
- PostgreSQL
TypeScript
await manta.updateRecords({
table: "products",
data: [
{
name: "Product A",
price: 50,
validation: {
name: { minLength: 5 },
price: { greaterThan: 25 },
},
},
{
name: "Product B",
price: 200,
validation: {
price: { greaterThan: 150 },
},
},
],
where: { status: "Active" },
});
TypeScript
await manta.updateRecords({
db: "inventory_pg",
table: "products",
data: [
{
name: "Product A",
price: 50,
validation: {
name: { minLength: 5 },
price: { greaterThan: 25 },
},
},
{
name: "Product B",
price: 200,
validation: {
price: { greaterThan: 150 },
},
},
],
where: { status: "Active" },
});
Validation rules
The following validation constraints are supported:
| Rule | Type | Description |
|---|---|---|
required | boolean | The field must exist and not be empty. |
minLength | number | The minimum required string length. |
maxLength | number | The maximum allowed string length. |
format | string | A predefined format (for example email, url, date, number). |
regex | RegExp | string | A custom regular expression pattern. |
enum | any[] | A restricted set of allowed values. |
greaterThan | number | Numeric value must be strictly greater than the specified number. |
lessThan | number | Numeric value must be strictly less than the specified number. |
greaterOrEqual | number | Numeric value must be greater than or equal to the specified number. |
lessOrEqual | number | Numeric value must be less than or equal to the specified number. |