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

ParameterTypeRequiredDescription
dbNamestringYesThe database slug
tableNamestringYesThe table to delete from
targetIDstring | numberNoThe id of the record to delete. Either targetID or deleteSpec is required
deleteSpecobjectNoField-value conditions for deletion (see below)
apiKeystringNoAPI key. Falls back to DATASQUIREL_API_KEY environment variable

deleteSpec.deleteKeyValues

An array of conditions. Each condition has:

FieldTypeDescription
keystringThe field name to match
valuestring | number | nullThe value to match against
operatorstringComparison 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.