DELETE
Delete one or more records from a table using the Datasquirel REST API or npm package.Overview
Use the DELETE endpoint to remove records from a table. You can delete by a specific record ID or by matching field values.
npm Package
Delete by ID
import datasquirel from "@moduletrace/datasquirel"; const result = await datasquirel.crud.delete({ dbName: "my_database", tableName: "users", targetID: 42, apiKey: process.env.DATASQUIREL_API_KEY, });
Delete by Field Value
const result = await datasquirel.crud.delete({ dbName: "my_database", tableName: "sessions", deleteSpec: { deleteKeyValues: [ { key: "user_id", value: 42, operator: "=" }, ], }, apiKey: process.env.DATASQUIREL_API_KEY, });
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
dbName | string | Yes | The database slug |
tableName | string | Yes | The table to delete from |
targetID | string | number | No | The id of the record to delete. Either targetID or deleteSpec is required |
deleteSpec | object | No | Field-value conditions for deletion (see below) |
apiKey | string | No | API key. Falls back to DATASQUIREL_API_KEY environment variable |
deleteSpec.deleteKeyValues
An array of conditions. Each condition has:
| Field | Type | Description |
|---|---|---|
key | string | The field name to match |
value | string | number | null | The value to match against |
operator | string | Comparison operator — "=", "!=", ">", "<", etc. Defaults to "=" |
REST API
DELETE /api/v1/crud/{dbName}/{tableName}/{id} DELETE /api/v1/crud/{dbName}/{tableName}
Headers:
Authorization: Bearer YOUR_API_KEY Content-Type: application/json
Body (when deleting by field value):
{ "deleteKeyValues": [ { "key": "user_id", "value": 42, "operator": "=" } ] }
Response
{ "success": true, "payload": 1 }
A successful response returns success: true and payload with the number of deleted rows.