Beispiel #1
0
def player_insert_on_conflict_update():
    if Config.db_engine == "mysql":
        query_insert = mysql_insert(scoreboard)
        return query_insert.on_duplicate_key_update(
            name=query_insert.inserted.name,
            team=query_insert.inserted.team,
            alive=query_insert.inserted.alive,
            ping=query_insert.inserted.ping,
            kills=query_insert.inserted.kills,
            headshots=query_insert.inserted.headshots,
            assists=query_insert.inserted.assists,
            deaths=query_insert.inserted.deaths,
            shots_fired=query_insert.inserted.shots_fired,
            shots_hit=query_insert.inserted.shots_hit,
            mvps=query_insert.inserted.mvps,
            score=query_insert.inserted.score,
            disconnected=query_insert.inserted.disconnected)
    elif Config.db_engine == "psycopg2":
        query_insert = postgresql_insert(scoreboard)
        return postgresql_insert(scoreboard).on_conflict_do_update(
            set_=dict(name=query_insert.inserted.name,
                      team=query_insert.inserted.team,
                      alive=query_insert.inserted.alive,
                      ping=query_insert.inserted.ping,
                      kills=query_insert.inserted.kills,
                      headshots=query_insert.inserted.headshots,
                      assists=query_insert.inserted.assists,
                      deaths=query_insert.inserted.deaths,
                      shots_fired=query_insert.inserted.shots_fired,
                      shots_hit=query_insert.inserted.shots_hit,
                      mvps=query_insert.inserted.mvps,
                      score=query_insert.inserted.score,
                      disconnected=query_insert.inserted.disconnected))
    else:
        return scoreboard.insert
Beispiel #2
0
def compile_upsert_postgresql(upsert_stmt, compiler, **kwargs):
    # See https://docs.sqlalchemy.org/en/14/dialects/postgresql.html#insert-on-conflict-upsert
    insert_stmt = postgresql_insert(upsert_stmt.table)
    pk_col_names = [c.name for c in upsert_stmt.pk_columns]
    update_dict = {
        c.name: c
        for c in insert_stmt.excluded if c.name not in pk_col_names
    }
    insert_stmt = insert_stmt.on_conflict_do_update(
        index_elements=pk_col_names, set_=update_dict)
    return compiler.process(insert_stmt)
def on_user_conflict() -> Any:
    """Used for updating a users on conflict.
    """

    if Config.db_engine == "mysql":
        query_insert = mysql_insert(user_table)
        return query_insert.on_duplicate_key_update(
            name=query_insert.inserted.name,
            timestamp=query_insert.inserted.timestamp)
    elif Config.db_engine == "psycopg2":
        query_insert = postgresql_insert(user_table)
        return query_insert.on_conflict_do_update(
            set_=dict(name=query_insert.inserted.name,
                      timestamp=query_insert.inserted.timestamp))
    else:
        return user_table.insert
def on_scoreboard_conflict() -> Any:
    """Used for updating a player on a scoreboard on conflict.
    """

    if Config.db_engine == "mysql":
        query_insert = mysql_insert(scoreboard_table)
        return query_insert.on_duplicate_key_update(
            team=query_insert.inserted.team,
            alive=query_insert.inserted.alive,
            ping=query_insert.inserted.ping,
            kills=scoreboard_table.c.kills + query_insert.inserted.kills,
            headshots=scoreboard_table.c.headshots +
            query_insert.inserted.headshots,
            assists=scoreboard_table.c.assists + query_insert.inserted.assists,
            deaths=scoreboard_table.c.deaths + query_insert.inserted.deaths,
            shots_fired=scoreboard_table.c.shots_fired +
            query_insert.inserted.shots_fired,
            shots_hit=scoreboard_table.c.shots_hit +
            query_insert.inserted.shots_hit,
            mvps=scoreboard_table.c.mvps + query_insert.inserted.mvps,
            score=scoreboard_table.c.score + query_insert.inserted.score,
            disconnected=query_insert.inserted.disconnected)
    elif Config.db_engine == "psycopg2":
        query_insert = postgresql_insert(scoreboard_table)
        return query_insert.on_conflict_do_update(
            set_=dict(team=query_insert.inserted.team,
                      alive=query_insert.inserted.alive,
                      ping=query_insert.inserted.ping,
                      kills=scoreboard_table.c.kills +
                      query_insert.inserted.kills,
                      headshots=scoreboard_table.c.headshots +
                      query_insert.inserted.headshots,
                      assists=scoreboard_table.c.assists +
                      query_insert.inserted.assists,
                      deaths=scoreboard_table.c.deaths +
                      query_insert.inserted.deaths,
                      shots_fired=scoreboard_table.c.shots_fired +
                      query_insert.inserted.shots_fired,
                      shots_hit=scoreboard_table.c.shots_hit +
                      query_insert.inserted.shots_hit,
                      mvps=scoreboard_table.c.mvps +
                      query_insert.inserted.mvps,
                      score=scoreboard_table.c.score +
                      query_insert.inserted.score,
                      disconnected=query_insert.inserted.disconnected))
    else:
        return scoreboard_table.insert
def on_statistic_conflict() -> Any:
    """Used for updating a statistics on conflict.
    """

    if Config.db_engine == "mysql":
        query_insert = mysql_insert(statistic_table)
        return query_insert.on_duplicate_key_update(
            kills=statistic_table.c.kills + query_insert.inserted.kills,
            headshots=statistic_table.c.headshots +
            query_insert.inserted.headshots,
            assists=statistic_table.c.assists + query_insert.inserted.assists,
            deaths=statistic_table.c.deaths + query_insert.inserted.deaths,
            shots_fired=statistic_table.c.shots_fired +
            query_insert.inserted.shots_fired,
            shots_hit=statistic_table.c.shots_hit +
            query_insert.inserted.shots_hit,
            mvps=statistic_table.c.mvps + query_insert.inserted.mvps)
    elif Config.db_engine == "psycopg2":
        query_insert = postgresql_insert(statistic_table)
        return query_insert.on_conflict_do_update(
            set_=dict(kills=statistic_table.c.kills +
                      query_insert.inserted.kills,
                      headshots=statistic_table.c.headshots +
                      query_insert.inserted.headshots,
                      assists=statistic_table.c.assists +
                      query_insert.inserted.assists,
                      deaths=statistic_table.c.deaths +
                      query_insert.inserted.deaths,
                      shots_fired=statistic_table.c.shots_fired +
                      query_insert.inserted.shots_fired,
                      shots_hit=statistic_table.c.shots_hit +
                      query_insert.inserted.shots_hit,
                      mvps=statistic_table.c.mvps +
                      query_insert.inserted.mvps))
    else:
        return statistic_table.insert