Esempio n. 1
0
def update_processed_events(event_ids):
    """
    Marks event ids as processed

    Attr:
        event_ids (list): Now processed event ids
    """
    parameters = ",".join(["%s"] * len(event_ids))
    db.write(
        f"UPDATE game_event SET processed = 1 WHERE event_id IN ({parameters})",
        event_ids,
    )
Esempio n. 2
0
def insert_game_event(game_id, event):
    """
    Inserts a new game event into the database

    Attr:
        game_id (str): The game this event belongs to
        event (dict): Event dictionary
    """
    event["id"] = utils.generate_id()
    db.write(
        "INSERT INTO game_event (event_id, game_id, data, processed, time_created) VALUES (%s, %s, %s, %s, %s)",
        [event["id"], game_id,
         json.dumps(event), 0,
         int(time.time())],
    )
Esempio n. 3
0
def insert_game(game):
    """
    Inserts a new Game object to the database

    Attr:
        game (Game): Game object to save
    """
    db.write(
        "INSERT INTO game (game_id, data, time_created, time_started, time_updated) VALUES (%s, %s, %s, %s, %s)",
        [
            game.game_id,
            json.dumps(game.get_sensitive_state()),
            game.time_created,
            game.time_started,
            game.time_updated,
        ],
    )
Esempio n. 4
0
def update_game(game):
    """
    Updates an existing Game object to the database

    Attr:
        game (Game): Game object to save
    """
    game.updated()
    db.write(
        "UPDATE game SET game_id = %s, data = %s, time_completed = %s, time_started = %s, time_updated = %s WHERE game_id = %s",
        [
            game.game_id,
            json.dumps(game.get_sensitive_state()),
            game.time_completed,
            game.time_started,
            game.time_updated,
            game.game_id,
        ],
    )