"""SQLAlchemy ORM models. This module defines the database ORM models that map to database tables. Models are used by repositories for data persistence. """ 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. Database table representation of blog posts. Maps to the 'posts' table with all post attributes. Attributes: id: Primary key as UUID string. title: Post title (max 200 chars). content: Post content (text). slug: URL-friendly unique identifier. author_id: Author reference. published: Publication status flag. tags: JSON array of tags. created_at: Creation timestamp. updated_at: Last update timestamp. Example: >>> post = PostORM(title="Post", content="...", slug="post", author_id="user-1") """ __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, )