From c04940fb9bdd490dcda92a4441c73c2148a065a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Ke=C3=9Fler?= Date: Thu, 10 Oct 2024 16:30:43 +0200 Subject: [PATCH] db interface: expand for new cert game tables --- src/hanabi/database/games_db_interface.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/hanabi/database/games_db_interface.py b/src/hanabi/database/games_db_interface.py index 1b9d0ca..115ad6e 100644 --- a/src/hanabi/database/games_db_interface.py +++ b/src/hanabi/database/games_db_interface.py @@ -8,18 +8,21 @@ from hanabi import logger from hanabi.database import conn, cur +def get_actions_table_name(cert_game: bool): + return "certificate_game_actions" if cert_game else "game_actions" -def store_actions(game_id: int, actions: List[hanabi.hanab_game.Action]): + +def store_actions(game_id: int, actions: List[hanabi.hanab_game.Action], cert_game: bool = False): vals = [] for turn, action in enumerate(actions): vals.append((game_id, turn, action.type.value, action.target, action.value or 0)) psycopg2.extras.execute_values( cur, - "INSERT INTO game_actions (game_id, turn, type, target, value) " + "INSERT INTO {} (game_id, turn, type, target, value) " "VALUES %s " "ON CONFLICT (game_id, turn) " - "DO NOTHING", + "DO NOTHING".format(get_actions_table_name(cert_game)), vals ) conn.commit() @@ -41,10 +44,10 @@ def store_deck_for_seed(seed: str, deck: List[hanabi.hanab_game.DeckCard]): conn.commit() -def load_actions(game_id: int) -> List[hanabi.hanab_game.Action]: - cur.execute("SELECT type, target, value FROM game_actions " +def load_actions(game_id: int, cert_game: bool = False) -> List[hanabi.hanab_game.Action]: + cur.execute("SELECT type, target, value FROM {} " "WHERE game_id = %s " - "ORDER BY turn ASC", + "ORDER BY turn ASC".format(get_actions_table_name(cert_game)), (game_id,)) actions = [] for action_type, target, value in cur.fetchall():