Syntax
First, import the MantaClient from the library, see Getting Started:
Before using this method, ensure that the target database has been set up and configured.
This method accepts a single object as its parameter.
manta.deleteRecords(object);
Basic usage​
Single condition-based delete​
This example deletes the single user record where the id is 10.
const result = await manta.deleteRecords({
table: "user",
where: { id: 10 },
});
Multiple records delete (OR logic)​
This example deletes all users whose id is either 10 or 11. The array format in where is interpreted with an implicit OR condition.
const result = await manta.deleteRecords({
table: "user",
where: [{ id: 10 }, { id: 11 }], // Equivalent to { or: [{ id: 10 }, { id: 11 }] }
});
Delete all records​
To prevent accidental data loss, deleting all records in a table requires the options.allowAll flag to be set to true. The where parameter is omitted in this case.
const result = await manta.deleteRecords({
table: "log",
options: { allowAll: true }, // Safety measure required for full-table delete
});
Response​
Success response​
The response includes the counts of hard-deleted and soft-deleted records.
{
"status": "success",
"code": 200,
"data": {
"deleted": 5, // Count of hard-deleted records
"softDeleted": 0 // Count of soft-deleted records (if softDelete: true was used)
},
"errors": []
}
Error response​
An error response will be returned if the operation fails (e.g., due to transactional rollback, permission issues, or internal database failure).
{
"message": "Transaction failed during delete operation.",
"state": false,
"errors": [
{
"code": "DB_CONSTRAINT_VIOLATION",
"message": "Cannot delete record due to foreign key constraint."
}
],
"statusCode": 500
}