Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

database: database_connection.py: add get game from id and the other way around #63

Merged
merged 1 commit into from
Jan 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions dnd-bot/dnd_bot/database/database_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,29 @@ def get_all_game_tokens():
DatabaseConnection.connection.commit()

return tokens

@staticmethod
def get_id_game_from_game_token(token: str) -> int | None:
"""returns database game id based on the token, None if the query fails
"""
DatabaseConnection.cursor.execute(f'SELECT id_game FROM public."Game" WHERE token = %s', token)
game_id = DatabaseConnection.cursor.fetchone()
DatabaseConnection.connection.commit()

if not game_id:
return None

return game_id

@staticmethod
def get_game_token_from_id_game(id_game: int) -> str | None:
"""returns game token based on database game id, None if the query fails
"""
DatabaseConnection.cursor.execute(f'SELECT token FROM public."Game" WHERE id_game = %s', id_game)
game_token = DatabaseConnection.cursor.fetchone()
DatabaseConnection.connection.commit()

if not game_token:
return None

return game_token