Spaces:
Paused
Paused
Download models/base.py from 3SCError404/nexus: direct link, hf CLI and curl.
- Browser
- Download file 1.18 kB
-
https://huggingface.co/spaces/3SCError404/nexus/resolve/main/models/base.py
- Command line
-
hf download hf://spaces/3SCError404/nexus/models/base.py
-
curl -L -o base.py https://huggingface.co/spaces/3SCError404/nexus/resolve/main/models/base.py
1.18 kB
| """ | |
| Base model mixin providing id, created_at, updated_at for all entities. | |
| """ | |
| import uuid | |
| from datetime import datetime | |
| from sqlalchemy import Column, DateTime | |
| from sqlalchemy.dialects.postgresql import UUID | |
| class TimestampMixin: | |
| """Adds created_at and updated_at columns to any model.""" | |
| created_at = Column( | |
| DateTime(timezone=False), | |
| default=datetime.utcnow, | |
| nullable=False, | |
| ) | |
| updated_at = Column( | |
| DateTime(timezone=False), | |
| default=datetime.utcnow, | |
| onupdate=datetime.utcnow, | |
| nullable=False, | |
| ) | |
| class PrimaryKeyMixin: | |
| """Adds a UUID primary key to any model.""" | |
| id = Column( | |
| UUID(as_uuid=True), | |
| primary_key=True, | |
| default=uuid.uuid4, | |
| index=True, | |
| ) | |
| class SoftDeleteMixin: | |
| """Adds soft delete capability to any model.""" | |
| deleted_at = Column( | |
| DateTime(timezone=False), | |
| nullable=True, | |
| ) | |
| deleted_by_id = Column( | |
| UUID(as_uuid=True), | |
| nullable=True, | |
| doc="ID of the user who performed the soft delete" | |
| ) | |
| def is_deleted(self) -> bool: | |
| return self.deleted_at is not None | |