from collections.abc import Sequence import sqlalchemy as sa from ows_text_campaigns.adapters.db import Repository from ows_text_campaigns.assets.models import Asset class AssetRepository(Repository[Asset]): def get_by_id_for_object( self, *, asset_id: str, object_type: str, object_id: str ) -> Asset | None: """Retrieve an asset by its object type and ID.""" query = sa.select(Asset).where( Asset.id == asset_id, Asset.object_type == object_type, Asset.object_id == object_id, ) return self.db.session.execute(query).scalar_one_or_none() def find_by_ids_for_object( self, *, asset_ids: list[str], object_type: str, object_id: str ) -> Sequence[Asset]: """Retrieve multiple assets by their object type and IDs.""" if not asset_ids: return [] query = sa.select(Asset).where( Asset.id.in_(asset_ids), Asset.object_type == object_type, Asset.object_id == object_id, ) return self.db.session.execute(query).scalars().all()