Skip to main content

Conditional updates

Use the where parameter with friendly syntax operators to target specific records for an update.

Simple conditions

Update records based on a single field match.

TypeScript
// Update products in a specific category
await manta.updateRecords({
table: "products",
data: { status: "discontinued" },
where: { category_id: "cat-1" },
});

Logical operators (AND/OR)

Combine multiple filters to refine your update scope.

AND conditions Update records that match all provided criteria.

TypeScript
// Update products that are electronics AND under $50
await manta.updateRecords({
table: "products",
data: { status: "clearance" },
where: {
and: [{ category_id: "electronics" }, { price: { lessThan: 50 } }],
},
});

OR conditions Update records that match at least one of the provided criteria.

TypeScript
// Update products that are either electronics OR over $100
await manta.updateRecords({
table: "products",
data: { featured: true },
where: {
or: [{ category_id: "electronics" }, { price: { greaterThan: 100 } }],
},
});

Supported operators

The where clause supports the following friendly syntax operators:

OperatorDescriptionExample
equalsEqual to{ status: { equals: 'active' } }
notEqualsNot equal to{ status: { notEquals: 'inactive' } }
greaterThanGreater than{ price: { greaterThan: 100 } }
greaterOrEqualGreater than or equal{ age: { greaterOrEqual: 18 } }
lessThanLess than{ price: { lessThan: 50 } }
lessOrEqualLess than or equal{ age: { lessOrEqual: 65 } }
inValue is present in the array{ category: { in: ['A', 'B'] } }
notInValue is not present in the array{ status: { notIn: ['banned'] } }

Operator examples

The following examples demonstrate how to use array and comparison operators in the where clause.

Array operators (in and notIn)

Use the in operator to match records where a field value is present in a list of allowed values.

TypeScript
// Update users whose role is either 'admin', 'moderator', or 'editor'
await manta.updateRecords({
table: "users",
data: { access_level: "high" },
where: {
role: {
in: ["admin", "moderator", "editor"],
},
},
});

Use the notIn operator to match records where a field value is present in a list of allowed values.

TypeScript
// Update products NOT currently on the 'sale' or 'clearance' status
await manta.updateRecords({
table: "products",
data: { campaign: "Holiday" },
where: {
status: {
notIn: ["sale", "clearance"],
},
},
});

Comparison operators

Comparison operators like greaterThan and lessOrEqual are essential for working with numeric and date fields.

TypeScript
// Update products where the stock quantity is low
await manta.updateRecords({
table: "products",
data: { restock: true },
where: {
stock_quantity: { lessThan: 10 },
},
});
TypeScript
// Update orders created in 2024 or later
await manta.updateRecords({
table: "orders",
data: { archived: false },
where: {
created_at: {
greaterOrEqual: 2024,
},
},
});