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.
- Manta data table
- PostgreSQL
// Update products in a specific category
await manta.updateRecords({
table: "products",
data: { status: "discontinued" },
where: { category_id: "cat-1" },
});
// Update products in an external PostgreSQL database
await manta.updateRecords({
db: "inventory_pg",
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.
// 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.
// 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:
| Operator | Description | Example |
|---|---|---|
equals | Equal to | { status: { equals: 'active' } } |
notEquals | Not equal to | { status: { notEquals: 'inactive' } } |
greaterThan | Greater than | { price: { greaterThan: 100 } } |
greaterOrEqual | Greater than or equal | { age: { greaterOrEqual: 18 } } |
lessThan | Less than | { price: { lessThan: 50 } } |
lessOrEqual | Less than or equal | { age: { lessOrEqual: 65 } } |
in | Value is present in the array | { category: { in: ['A', 'B'] } } |
notIn | Value 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.
- Manta data table
- PostgreSQL
// 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"],
},
},
});
// Update users whose role is either 'admin', 'moderator', or 'editor'
const result = await manta.updateRecords({
db: "users_pg",
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.
- Manta data table
- PostgreSQL
// Update products NOT currently on the 'sale' or 'clearance' status
await manta.updateRecords({
table: "products",
data: { campaign: "Holiday" },
where: {
status: {
notIn: ["sale", "clearance"],
},
},
});
const result = await manta.updateRecords({
// Update products NOT currently on the 'sale' or 'clearance' status
db: "products_pg",
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.
- Manta data table
- PostgreSQL
// Update products where the stock quantity is low
await manta.updateRecords({
table: "products",
data: { restock: true },
where: {
stock_quantity: { lessThan: 10 },
},
});
// Update products where the stock quantity is low
await manta.updateRecords({
db: "inventory_db",
table: "products",
data: { restock: true },
where: {
stock_quantity: { lessThan: 10 },
},
});
- Manta data table
- PostgreSQL
// Update orders created in 2024 or later
await manta.updateRecords({
table: "orders",
data: { archived: false },
where: {
created_at: {
greaterOrEqual: 2024,
},
},
});
// Update orders created in 2024 or later
await manta.updateRecords({
db: "inventory_db",
table: "orders",
data: { archived: false },
where: {
created_at: {
greaterOrEqual: 2024,
},
},
});