Principle:APIJSON APIJSON Fake Delete
| Knowledge Sources | |
|---|---|
| Domains | ORM, Soft_Delete, Data_Management |
| Last Updated | 2026-10-11 00:00 GMT |
Overview
A soft-delete pattern that transparently converts DELETE operations into UPDATE statements with a deleted-flag column, preserving data recoverability while automatically filtering deleted records from query results.
Description
Fake Delete (soft delete) is a data management pattern where records are not physically removed from the database. Instead, a designated column (e.g., isDeleted) is set to a "deleted" value, and the record remains in the table. Subsequent queries automatically filter out records marked as deleted.
In APIJSON, fake-delete is:
- Configurable: Per-table configuration via the Access table, specifying deletedKey (column name), notDeletedValue (active value), and deletedValue (deleted value)
- Transparent: Clients send normal DELETE requests; the framework converts them to UPDATEs internally
- Automatic filtering: GET queries automatically append deletedKey = notDeletedValue to the WHERE clause
- JOIN-aware: Both SQL JOINs and APP JOINs apply fake-delete filters to joined tables
The problem solved is data loss from hard deletes. Physical deletion is irreversible and loses audit trail information. Soft-delete preserves data for recovery, auditing, and referential integrity while presenting a "deleted" view to users.
Usage
Use this principle when:
- Deleted records may need to be recovered
- Audit trails require preserving historical data
- Referential integrity would break with hard deletes
- Regulatory compliance requires data retention
Theoretical Basis
# Abstract algorithm (NOT real implementation):
def fake_delete(table, conditions):
config = FAKE_DELETE_MAP.get(table)
if config is None:
return real_delete(table, conditions) # Fallback to hard delete
# Convert DELETE to UPDATE
deleted_key = config["deletedKey"]
deleted_value = config["deletedValue"]
sql = f"UPDATE {table} SET {deleted_key} = {deleted_value} WHERE {conditions}"
return execute(sql)
def auto_filter_get(table, where_clause):
config = FAKE_DELETE_MAP.get(table)
if config is None:
return where_clause
# Append active filter
filter = f"{config['deletedKey']} = {config['notDeletedValue']}"
if where_clause:
return f"{where_clause} AND {filter}"
return filter