Soft delete
rn_forge.fastapi.soft_delete
Soft delete over FastAPI (AIP-164): DELETE and :undelete routes and showDeleted.
Persistence is the application's: :func:soft_delete_router takes a store
dependency that implements :class:SoftDeleteStore.
SoftDeleteState(row, version, delete_time)
dataclass
A row as :class:SoftDeleteStore reports it.
Attributes:
| Name | Type | Description |
|---|---|---|
row |
Any
|
The stored row. |
version |
int | None
|
The row's version, or |
delete_time |
datetime | None
|
When the row was soft-deleted; |
SoftDeleteStore
Bases: Protocol
Finds, soft-deletes and restores one resource.
The store owns the transaction and supplies the time recorded as
delete_time.
find(id)
async
Return the row with id, deleted or not, or None when it does not exist.
soft_delete(id)
async
Soft-delete the row and return it.
undelete(id)
async
Restore the row and return it.
show_deleted_param()
Return a dependency yielding whether the request includes soft-deleted resources.
showDeleted is true or 1 (any case) to include them; any other
value, or none, excludes them.
soft_delete_router(collection, *, response_model, resource_label, store, require_if_match=False, codec=None, dependencies=())
Build DELETE {collection}/{id} and POST {collection}/{id}:undelete.
DELETE soft-deletes and answers 200 with the resource, as
response_model dumped by alias. A missing or already deleted resource is a
404 reading {resource_label} {id} not found. :undelete restores the
resource and answers 200 with it; a live resource is a 409 reading
{resource_label} {id} is not deleted.
On a versioned resource both honour If-Match after those checks (428,
400 or 412), and answer with the new ETag. The store is not asked to
write after a failure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
collection
|
str
|
The collection path, for example |
required |
response_model
|
type[BaseModel]
|
The model of one resource. |
required |
resource_label
|
str
|
The resource's name in problem details, for example |
required |
store
|
Callable[..., SoftDeleteStore]
|
A dependency returning the :class: |
required |
require_if_match
|
bool
|
When |
False
|
codec
|
ETagCodec | None
|
The validator format; |
None
|
dependencies
|
Sequence[Depends]
|
Dependencies of the route, as for |
()
|
Returns:
| Type | Description |
|---|---|
APIRouter
|
The router. |