Skip to content

DB Delete ​

The DB Delete block permanently removes records from a table. It passes on how many records it deleted, and what they looked like just before.

When to use it ​

  • Remove something the user asked to delete, like a comment or an account.
  • Clean up expired data, like old sessions or tokens.
  • Don't use it when you may want the data back. Mark the record as deleted with DB Update instead. A delete can't be undone (unless it runs inside a DB Transaction that rolls back).
  • Don't use it without conditions unless you mean to empty the table. See the warning below.

Inputs ​

FieldRequiredDefaultWhat it does
ConnectionYesnoneThe database integration to use.
Table NameYesnoneThe table (or collection) to delete from.
ConditionsNonone (every record)Rules to find the records to delete, for example id equals 5. See DB Conditions. A condition whose value is undefined is skipped.
Save output to variableNooffStore the result in outputs.<name>.

Skipped conditions delete every record

If every condition is skipped, every record in the table is deleted. Make sure at least one condition always has a value.

Outputs ​

HandleWhen it is used
Next (right)The delete worked. The next block receives { count, affected }.
json
{ "count": 2, "affected": [{ "id": 4, "status": "cancelled" }, { "id": 9, "status": "cancelled" }] }
  • count: how many records were deleted. 0 when nothing matched.
  • affected: the deleted records, as they were just before the delete.

Example ​

Delete a comment, but only when it belongs to the caller.

FieldValue
Connectionmain-db
Table Namecomments
Conditionsid = js:getRouteParam('id') AND author_id = js:userId

If the comment doesn't exist or belongs to someone else, the next block receives { "count": 0, "affected": [] }. Add an If Condition with input.count === 0 that leads to a 404 Response.

How it behaves ​

  • No match is not an error. The output is { "count": 0, "affected": [] }.
  • Every deleted record is returned, so deleting a large table returns a large output.
  • Database errors (bad connection, missing table or column) go to the Error Handler.
  • It replaces the flowing data with the result.

Released under the Apache License 2.0. Enterprise features are under the Fluxify Enterprise Edition License.