"""LabelTerritoryException Model. This LabelTerritoryException model uses sqlalchemy. """ from oto import response from sqlalchemy import Column from sqlalchemy.dialects.mysql import INTEGER from sqlalchemy.dialects.mysql import BIGINT from sqlalchemy.dialects.mysql import SMALLINT from prs.connectors import mysql class LabelTerritoryException(mysql.ppb_model): """Table definition for label_territory_exception table.""" __tablename__ = 'label_territory_exception' exception_id = Column( 'exception_id', INTEGER(unsigned=True), autoincrement=True, primary_key=True, nullable=False) label_id = Column('label_id', BIGINT(unsigned=True), nullable=False) country_id = Column('country_id', SMALLINT(unsigned=True), nullable=False) @mysql.wrap_db_errors def get_label_id_by_country_id(country_id): """Get label ids by country id. Args: country_id (int): Country id to fetch label id(s). Returns: response.Response: Response contains list describing label id/ids or validation message. """ with mysql.ppb_db_session() as session: label_ids = session.query(LabelTerritoryException.label_id).filter_by( country_id=country_id).all() return response.Response(message={'label_ids': [ tuple(label_object) for label_object in label_ids]})