-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add soft deletion mixin for model handling
Generated-by: aiautocommit
- Loading branch information
1 parent
53d1d65
commit 2e24e26
Showing
3 changed files
with
32 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
from .soft_delete import SoftDeletionMixin | ||
from .timestamps import TimestampsMixin | ||
from .typeid import TypeIDMixin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from datetime import datetime | ||
|
||
import sqlalchemy as sa | ||
from sqlmodel import Field | ||
|
||
|
||
class SoftDeletionMixin: | ||
deleted_at: datetime = Field( | ||
default=None, | ||
nullable=True, | ||
# TODO https://github.com/fastapi/sqlmodel/discussions/1228 | ||
sa_type=sa.DateTime(timezone=True), # type: ignore | ||
) | ||
|
||
def soft_delete(self): | ||
self.deleted_at = datetime.now() | ||
raise NotImplementedError("Soft deletion is not implemented") |