Spaces:
Running on T4
Running on T4
Download backend/app/common/base_model.py from modventures/baseball-engine: direct link, hf CLI and curl.
- Browser
- Download file 1.13 kB
-
https://huggingface.co/spaces/modventures/baseball-engine/resolve/main/backend/app/common/base_model.py
- Command line
-
hf download hf://spaces/modventures/baseball-engine/backend/app/common/base_model.py
-
curl -L -o base_model.py https://huggingface.co/spaces/modventures/baseball-engine/resolve/main/backend/app/common/base_model.py
1.13 kB
| """Declarative base and the column mixins every table reuses.""" | |
| import uuid | |
| from datetime import datetime | |
| from sqlalchemy import DateTime, MetaData, func, text | |
| from sqlalchemy.dialects.postgresql import UUID | |
| from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column | |
| NAMING_CONVENTION = { | |
| "ix": "ix_%(table_name)s_%(column_0_N_name)s", | |
| "uq": "uq_%(table_name)s_%(column_0_N_name)s", | |
| "ck": "ck_%(table_name)s_%(constraint_name)s", | |
| "fk": "fk_%(table_name)s_%(column_0_name)s_%(referred_table_name)s", | |
| "pk": "pk_%(table_name)s", | |
| } | |
| class Base(DeclarativeBase): | |
| metadata = MetaData(naming_convention=NAMING_CONVENTION) | |
| class IdMixin: | |
| id: Mapped[uuid.UUID] = mapped_column( | |
| UUID(as_uuid=True), primary_key=True, default=uuid.uuid4, server_default=text("gen_random_uuid()") | |
| ) | |
| class CreatedAtMixin: | |
| created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now()) | |
| class TimestampMixin(CreatedAtMixin): | |
| updated_at: Mapped[datetime] = mapped_column( | |
| DateTime(timezone=True), server_default=func.now(), onupdate=func.now() | |
| ) | |