supercontest.dbsession.commits
Simple commit wrappers for writing data to the database.
Functions
Gets the paid league for the current season, then adds the user to it. |
|
Adds a known user to a known role. |
|
Gets the paid league for the current season, then adds the users to it. |
|
Changes the status of a game. |
|
Creates a new role. |
|
Wrapper around deleting rows. |
|
Writes the lines and initial opponent info to the database. |
|
Deletes, updates, and inserts pick objects to the database as necessary. |
|
Commits the scores to the database (insert and/or update). |
- supercontest.dbsession.commits.add_user_to_current_paid_league(user_email: str) None
Gets the paid league for the current season, then adds the user to it.
- Parameters:
user_email – User email.
- supercontest.dbsession.commits.add_user_to_role(user_email: str, role_name: str) None
Adds a known user to a known role.
- Parameters:
user_email – The user to add.
role_name – The name of the role to provide.
- supercontest.dbsession.commits.add_users_to_current_paid_league(user_emails: list[str]) None
Gets the paid league for the current season, then adds the users to it.
- Parameters:
user_emails – User emails.
- supercontest.dbsession.commits.change_game_status(game_id: int, status_name: str) None
Changes the status of a game.
- Parameters:
game_id – The ID of the matchup that you’re changing the status for.
status_name – The name of the status to change to (via FK to statuses table).
- supercontest.dbsession.commits.create_role(name: str) Role
Creates a new role. Easy, exemplary.
- Parameters:
name – Name of new role (typically first-letter-capitalized).
- Returns:
Newly created role object.
- supercontest.dbsession.commits.delete_rows(rows: list[Game | Pick]) None
Wrapper around deleting rows. You may delete one or multiple.
- Parameters:
rows – The rows to delete.
- supercontest.dbsession.commits.insert_contestants(week_id: int, linesfetch: list[LinesFetch]) None
Writes the lines and initial opponent info to the database. All cleaning is done before this.
- Parameters:
week_id – The ID of the week to write lines for.
linesfetch – The return from
fetch_lines().
- supercontest.dbsession.commits.write_picks(old_pick_objs_update: list[Pick], new_pick_contestant_objs: list[Contestant], user_id: int) None
Deletes, updates, and inserts pick objects to the database as necessary. The caller already checked which existing picks to keep. So we have a remainder to update.
If there’s the same number of existing picks and new picks, it will update them.
If there are more existing picks than new picks, it will update for the new and delete the remaining rows from existing.
If there are more new picks than existing picks, it will update the existing and then insert the remainder for the new.
All validity of the picks must be analyzed prior to this function.
- Parameters:
old_pick_objs_update – Existing pick objects to update.
new_pick_contestant_objs – Contestant objects for the new picks.
user_id – The ID of the user submitting these picks.
- supercontest.dbsession.commits.write_scores(games: list[Game], scores: list[ScoresFetch]) None
Commits the scores to the database (insert and/or update). Games and scores must be in the same corresponding order.
- Parameters:
games – The return from
fetch_scores().scores – The return from
fetch_scores().
- Raises:
ValueError – If one of home/visitor doesn’t match favorite/underdog.