Transactional delete
Set options.transactional: true to treat all primary and nested deletions as a single operation. If any part of the operation fails, the entire transaction rolls back, ensuring no data is partially deleted.
Global transactional delete
When this flag is set, the system ensures an "all-or-nothing" outcome. If a record is not found or a constraint is violated, the API returns a 404 or 500 error, and no changes are committed to the database.
- Manta Studio
- PostgreSQL
await manta.deleteRecords({
table: "user",
where: [{ status: "inactive" }, { role: "guest" }],
options: { transactional: true }, // Rollback if any user deletion fails
});
await manta.deleteRecords({
db: "production_db",
table: "user",
where: [{ status: "inactive" }, { role: "guest" }],
options: { transactional: true },
});
Chunked deletes
Use options.chunkSize to process a large number of deletions in smaller batches. This is a recommended practice to prevent timeouts and memory issues when deleting thousands of records.
- Manta Studio
- PostgreSQL
// Delete old logs in batches of 500
await manta.deleteRecords({
table: "logs",
where: { createdAt: { lessThan: "2024-01-01" } },
options: { chunkSize: 500 },
});
// Delete old logs in batches of 500
await manta.deleteRecords({
db: "production_db",
table: "logs",
where: { createdAt: { lessThan: "2024-01-01" } },
options: { chunkSize: 500 },
});
Dry Run mode
Set options.dryRun: true to simulate the deletion process. The API returns a preview of the affected record count and data without performing any actual writes.
- Manta Studio
- PostgreSQL
const preview = await manta.deleteRecords({
table: "user",
where: { status: "inactive" },
options: { dryRun: true },
});
const preview = await manta.deleteRecords({
db: "production_db",
table: "user",
where: { status: "inactive" },
options: { dryRun: true },
});