Skip to main content

Conditional delete

Use the where parameter with friendly syntax operators to target specific records for deletion. These operators work identically across both internal Manta Tables and external PostgreSQL databases.

Simple conditions

Delete records that match a single specific criterion.

TypeScript
// Delete products that are discontinued
await manta.deleteRecords({
table: "products",
where: { status: "discontinued" },
});

AND conditions

Delete records that satisfy all specified criteria.

TypeScript
// Delete users who are 18 or older AND are currently inactive
await manta.deleteRecords({
table: "user",
where: {
and: [
{ age: { greaterOrEqual: 18 } },
{ status: { equals: "inactive" } }
],
},
});

OR conditions

Delete records that satisfy at least one of the specified criteria.

TypeScript
// Delete products that are either 'electronics' OR have a price over $500
await manta.deleteRecords({
table: "products",
where: {
or: [
{ category_id: "electronics" },
{ price: { greaterThan: 500 } }
],
},
});

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 mini-examples

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

In and Not In

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

TypeScript
// Delete users whose role is one of 'guest', 'trial', or 'inactive'
await manta.deleteRecords({
table: "users",
where: {
role: { in: ["guest", "trial", "inactive"] },
},
});
TypeScript
// Delete products whose tier value is NOT 'premium'
await manta.deleteRecords({
table: "products",
where: {
tier: {
notIn: ["premium"],
},
},
});

Comparison operators

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

TypeScript
// Delete all logs older than 30 days
await manta.deleteRecords({
table: "logs",
where: {
created_at: {
lessThan: "2025-09-20", // Assumes created_at is a date field
},
},
});
TypeScript
// Delete transactions below a minimum amount
await manta.deleteRecords({
table: "transactions",
where: {
amount: {
lessThan: 1.0,
},
},
});