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
|
||||
27
twitch-vod/src/twitch_vod/services/db/repository/vod.py
Normal file
27
twitch-vod/src/twitch_vod/services/db/repository/vod.py
Normal file
@@ -0,0 +1,27 @@
|
||||
from uuid import UUID
|
||||
from sqlmodel import Session, select
|
||||
from twitch_vod.services.db.models.vod import VOD
|
||||
from twitch_vod.services.db.postgres import postgres_engine
|
||||
|
||||
|
||||
def create_vod(bucket_video_key: str, bucket_msg_key: str):
|
||||
vod = VOD(vod_bucket_key=bucket_video_key, vod_bucket_message_key=bucket_msg_key)
|
||||
|
||||
session = Session(postgres_engine())
|
||||
|
||||
session.add(vod)
|
||||
session.commit()
|
||||
session.refresh(vod)
|
||||
|
||||
return vod
|
||||
|
||||
|
||||
def delete_vod(uuid: UUID):
|
||||
session = Session(postgres_engine())
|
||||
|
||||
statement = select(VOD).where(VOD.uuid == uuid)
|
||||
result = session.exec(statement)
|
||||
vod = result.one()
|
||||
|
||||
session.delete(vod)
|
||||
session.commit()
|
||||
Reference in New Issue
Block a user