import logging from sqlmodel import Session, select from twitch_vod.services.db.models.channel import Channel from twitch_vod.services.db.postgres import postgres_engine from twitch_vod.services.twitch.models.errors import ChannelDoesNotExist logger = logging.getLogger(__name__) def create_channel(channel_name): channel = Channel(channel_name=channel_name) session = Session(postgres_engine()) session.add(channel) session.commit() session.refresh(channel) return channel def delete_channel(channel_name: str): session = Session(postgres_engine()) statement = select(Channel).where(Channel.channel_name == channel_name) result = session.exec(statement) try: channel = result.one() session.delete(channel) session.commit() except Exception as e: logger.info("failed to find channel to delete") ChannelDoesNotExist(e) def get_all_channels(): session = Session(postgres_engine()) statement = select(Channel) result = session.exec(statement) channels = result.all() return channels