Skip to main content

Syntax

First, import the MantaClient from the library, see Getting Started:

💡Prerequisite

Before using this method, ensure that the target database has been set up and configured.

This method accepts a single object as its parameter.

TypeScript
manta.deleteRecords(object);

Basic usage​

Single condition-based delete​

This example deletes the single user record where the id is 10.

TypeScript
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.

TypeScript
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.

TypeScript
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.

JSON
{
"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).

JSON
{
"message": "Transaction failed during delete operation.",
"state": false,
"errors": [
{
"code": "DB_CONSTRAINT_VIOLATION",
"message": "Cannot delete record due to foreign key constraint."
}
],
"statusCode": 500
}