Examples
This section provides common, practical examples demonstrating various ways to use the deleteRecords() method.
💡PostgreSQL Support
For delete operations on PostgreSQL, providing the db parameter ensures the SDK targets the correct external database.
await manta.deleteRecords({
db: "your_postgres_db",
table: "logs",
where: { created_at: { lessThan: "2024-01-01" } }
});
Delete by ID list (In Operator)​
This example deletes all user records whose IDs are included in a specific array.
TypeScript
// Delete users with IDs 10, 11, or 12
await manta.deleteRecords({
table: "user",
where: { id: { in: [10, 11, 12] } },
});
Soft delete inactive users​
This example marks records as deleted by setting the deletedAt timestamp instead of permanently removing them.
TypeScript
// Soft delete inactive users and their related records
await manta.deleteRecords({
table: "user",
where: { status: "inactive" },
options: { softDelete: true },
with: { profile: { on: { from: "id", to: "userId" } } },
});
Conditional multi-table delete​
This example deletes a parent record (user) and its linked profile record, but only if the linked record meets a specific condition (verified: false).
TypeScript
// Delete user and their profile, but only if the profile is unverified
await manta.deleteRecords({
table: "user",
where: { id: 42 },
with: {
profile: {
on: { from: "id", to: "userId" },
when: { verified: { equals: false } },
},
},
});
Transactional delete for multiple criteria​
This example deletes records matching multiple criteria (inactive status OR guest role) and ensures that the entire batch deletion rolls back if any individual deletion fails.
TypeScript
// Delete all inactive users and guest users in a single transaction
await manta.deleteRecords({
table: "user",
where: { or: [{ status: "inactive" }, { role: "guest" }] },
options: { transactional: true },
});