import sqlalchemy as sa from anydi import singleton from ows_text_campaigns.adapters.db import DB, Repository from ows_text_campaigns.rosters.models import ArtistRosterMainRep class ArtistRosterMainRepRepository(Repository[ArtistRosterMainRep]): def exists_by_account_and_global_participant_id( self, vendor_id: int, subaccount_id: int, global_participant_id: str ) -> bool: stmt = sa.select( sa.select(1) .exists() .where( ArtistRosterMainRep.vendor_id == vendor_id, ArtistRosterMainRep.subaccount_id == subaccount_id, ArtistRosterMainRep.global_participant_id == global_participant_id, ) ) result = self.db.session.execute(stmt) return bool(result.scalar_one()) @singleton class ArtistRosterRepository: def __init__(self, db: DB) -> None: self.db = db def exists_by_artist_and_any_account( self, *, global_participant_id: str, vendor_ids: list[int], subaccount_ids: list[int], ) -> bool: if not vendor_ids and not subaccount_ids: return False query = self.db.query_from_template( "artist_roster/exists-by-artist-and-any-account.sql", context={ "global_participant_id": global_participant_id, "vendor_ids": vendor_ids, "subaccount_ids": subaccount_ids, }, ) result = self.db.session.execute(query) return bool(result.scalar_one())