Code Gen
This commit is contained in:
45
twitch-vod/src/twitch_vod/services/db/repository/channel.py
Normal file
45
twitch-vod/src/twitch_vod/services/db/repository/channel.py
Normal file
@@ -0,0 +1,45 @@
|
||||
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
|
||||
Reference in New Issue
Block a user