"""SQLAlchemy model for the artist_info table.""" from typing import Any from sqlalchemy import String, select from sqlalchemy.dialects.mysql import INTEGER from sqlalchemy.orm import Mapped, mapped_column, Session from contributor.connectors.mysql import BaseModel, db_session_wrap class ArtistInfo(BaseModel): __tablename__ = "artist_info" artist_id: Mapped[int] = mapped_column( INTEGER(unsigned=True), primary_key=True, autoincrement=True, ) name: Mapped[str | None] = mapped_column(String(255), nullable=True) vendor_id: Mapped[int | None] = mapped_column(INTEGER(unsigned=True), nullable=True) def to_dict(self) -> dict[str, Any]: """Convert the ArtistInfo instance to a dictionary.""" return { "artist_id": self.artist_id, "name": self.name, "vendor_id": self.vendor_id, } @db_session_wrap def get(session: Session, *, name: str, vendor_id: int) -> dict[str, Any] | None: """Get an artist by name and vendor_id.""" result = session.execute( select(ArtistInfo).where( ArtistInfo.name == name, ArtistInfo.vendor_id == vendor_id ) ).scalar_one_or_none() return result.to_dict() if result else None