Spaces:
Runtime error
Runtime error
Download app/persistence/database/base.py from fallingbody/interview-ai-live-backend: direct link, hf CLI and curl.
- Browser
- Download file 1.26 kB
-
https://huggingface.co/spaces/fallingbody/interview-ai-live-backend/resolve/main/app/persistence/database/base.py
- Command line
-
hf download hf://spaces/fallingbody/interview-ai-live-backend/app/persistence/database/base.py
-
curl -L -o base.py https://huggingface.co/spaces/fallingbody/interview-ai-live-backend/resolve/main/app/persistence/database/base.py
1.26 kB
| import uuid | |
| from datetime import datetime | |
| from sqlalchemy import Column, DateTime | |
| from sqlalchemy.orm import declarative_base | |
| from sqlalchemy.types import TypeDecorator, CHAR | |
| from sqlalchemy.dialects.postgresql import UUID as PG_UUID | |
| Base = declarative_base() | |
| class GUID(TypeDecorator): | |
| """ | |
| Platform-independent UUID type. | |
| """ | |
| impl = CHAR | |
| cache_ok = True | |
| def load_dialect_impl(self, dialect): | |
| if dialect.name == "postgresql": | |
| return dialect.type_descriptor(PG_UUID(as_uuid=True)) | |
| return dialect.type_descriptor(CHAR(36)) | |
| def process_bind_param(self, value, dialect): | |
| if value is None: | |
| return value | |
| if dialect.name == "postgresql" and isinstance(value, uuid.UUID): | |
| return value | |
| return str(uuid.UUID(str(value))) | |
| def process_result_value(self, value, dialect): | |
| if value is None: | |
| return value | |
| if isinstance(value, uuid.UUID): | |
| return value | |
| return uuid.UUID(value) | |
| class TimestampMixin: | |
| created_at = Column(DateTime, default=datetime.utcnow, nullable=False) | |
| updated_at = Column( | |
| DateTime, | |
| default=datetime.utcnow, | |
| onupdate=datetime.utcnow, | |
| nullable=False, | |
| ) | |