"""SQLAlchemy ORM models.""" from datetime import UTC, datetime from uuid import uuid4 from sqlalchemy import JSON, Boolean, DateTime, String, Text from sqlalchemy.orm import Mapped, declarative_base, mapped_column Base = declarative_base() class PostORM(Base): # type: ignore[valid-type,misc] """SQLAlchemy model for Blog Post.""" __tablename__ = "posts" id: Mapped[str] = mapped_column(String(36), primary_key=True, default=lambda: str(uuid4())) title: Mapped[str] = mapped_column(String(200), nullable=False) content: Mapped[str] = mapped_column(Text, nullable=False) slug: Mapped[str] = mapped_column(String(200), nullable=False, unique=True, index=True) author_id: Mapped[str] = mapped_column(String(100), nullable=False, index=True) published: Mapped[bool] = mapped_column(Boolean, default=False, nullable=False, index=True) tags: Mapped[list[str]] = mapped_column(JSON, default=list) created_at: Mapped[datetime] = mapped_column( DateTime(timezone=True), default=lambda: datetime.now(UTC), nullable=False, ) updated_at: Mapped[datetime] = mapped_column( DateTime(timezone=True), default=lambda: datetime.now(UTC), onupdate=lambda: datetime.now(UTC), nullable=False, )