"""Small shared Plex row lookups, so the get-by-rating_key pattern lives in one place.""" from sqlalchemy import select from sqlalchemy.orm import Session def by_rating_key(db: Session, model, rating_key: str): """The mirrored row for a Plex rating_key, or None. `model` is any of the rating_key-keyed Plex tables (PlexItem / PlexShow / PlexSeason / PlexCollection).""" return db.execute( select(model).where(model.rating_key == str(rating_key)) ).scalars().first()