Skip to main content

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.

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 },
},
},
});

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.

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" },
});

Validation rules

The following validation constraints are supported:

RuleTypeDescription
requiredbooleanThe field must exist and not be empty.
minLengthnumberThe minimum required string length.
maxLengthnumberThe maximum allowed string length.
formatstringA predefined format (for example email, url, date, number).
regexRegExp | stringA custom regular expression pattern.
enumany[]A restricted set of allowed values.
greaterThannumberNumeric value must be strictly greater than the specified number.
lessThannumberNumeric value must be strictly less than the specified number.
greaterOrEqualnumberNumeric value must be greater than or equal to the specified number.
lessOrEqualnumberNumeric value must be less than or equal to the specified number.