paper-dynasty-discord/in_game/gameplay_queries.py
Cal Corum 59fa207212 Add Card table
Updating factory to do all work in session fixture
2024-10-13 01:53:20 -05:00

21 lines
893 B
Python

import logging
from in_game.gameplay_models import Session, select, or_, Game
def get_games_by_channel(session: Session, channel_id: int) -> list[Game]:
return session.exec(select(Game).where(Game.channel_id == channel_id, Game.active)).all()
def get_channel_game_or_none(session: Session, channel_id: int) -> Game | None:
all_games = get_games_by_channel(session, channel_id)
if len(all_games) > 1:
err = 'Too many games found in get_channel_game_or_none'
logging.error(f'cogs.gameplay - get_channel_game_or_none - channel_id: {channel_id} / {err}')
raise LookupError(err)
elif len(all_games) == 0:
return None
return all_games[0]
def get_active_games_by_team(session: Session, team_id: int) -> list[Game]:
return session.exec(select(Game).where(Game.active, or_(Game.away_team_id == team_id, Game.home_team_id == team_id))).all()