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.
- Manta Studio
- PostgreSQL
TypeScript
// Delete products that are discontinued
await manta.deleteRecords({
table: "products",
where: { status: "discontinued" },
});
TypeScript
// Delete products that are discontinued
await manta.deleteRecords({
db: "products_pg",
table: "products",
where: { status: "discontinued" },
});
AND conditions
Delete records that satisfy all specified criteria.
- Manta Studio
- PostgreSQL
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" } }
],
},
});
TypeScript
// Delete users who are 18 or older AND are currently inactive
await manta.deleteRecords({
db: "products_pg",
table: "user",
where: {
and: [
{ age: { greaterOrEqual: 18 } },
{ status: { equals: "inactive" } }
],
},
});
OR conditions
Delete records that satisfy at least one of the specified criteria.
- Manta Studio
- PostgreSQL
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 } }
],
},
});
TypeScript
// Delete products that are either 'electronics' OR have a price over $500
await manta.deleteRecords({
db: "products_pg",
table: "products",
where: {
or: [
{ category_id: "electronics" },
{ price: { greaterThan: 500 } }
],
},
});
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 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.
- Manta Studio
- PostgreSQL
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 users whose role is one of 'guest', 'trial', or 'inactive'
await manta.deleteRecords({
db: "guests_pg",
table: "users",
where: {
role: { in: ["guest", "trial", "inactive"] },
},
});
- Manta Studio
- PostgreSQL
TypeScript
// Delete products whose tier value is NOT 'premium'
await manta.deleteRecords({
table: "products",
where: {
tier: {
notIn: ["premium"],
},
},
});
TypeScript
// Delete products whose tier value is NOT 'premium'
await manta.deleteRecords({
db: "products_pg",
table: "products",
where: {
tier: {
notIn: ["premium"],
},
},
});
Comparison operators
Comparison operators like greaterThan and lessOrEqual are essential for working with numeric and date fields.
- Manta Studio
- PostgreSQL
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 all logs older than 30 days
await manta.deleteRecords({
db: "inventory_pg",
table: "logs",
where: {
created_at: {
lessThan: "2025-09-20", // Assumes created_at is a date field
},
},
});
- Manta Studio
- PostgreSQL
TypeScript
// Delete transactions below a minimum amount
await manta.deleteRecords({
table: "transactions",
where: {
amount: {
lessThan: 1.0,
},
},
});
TypeScript
// Delete all logs older than 30 days
await manta.deleteRecords({
db: "inventory_pg",
table: "transactions",
where: {
amount: {
lessThan: 1.0,
},
},
});