"""Country Model. This Country model uses sqlalchemy. It's used to get information about country """ from oto import response from sqlalchemy import Column from sqlalchemy import SmallInteger from sqlalchemy import String from prs.connectors import mysql class Country(mysql.ar_model): """Table definition for country table.""" __tablename__ = 'country' country_id = Column( 'id', SmallInteger, primary_key=True, autoincrement=True, nullable=False) name = Column(String(45), nullable=False) @mysql.wrap_db_errors def get_country_name_by_id(country_id): """Get country name by country id. Args: country_id (int): Country id Returns: response.Response: Response with country name or error """ with mysql.ar_db_session() as session: country = session.query(Country).get(country_id) if not country: return response.create_not_found_response( 'country id:{} not found.'.format(country_id)) return response.Response(message={'name': country.name})