This commit is contained in:
2026-05-13 09:37:42 -04:00
parent ca3469376a
commit 2889993a7d
40 changed files with 1583 additions and 0 deletions

View 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

View 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()