Create new python file for handling sqlalchemy. Removes circular import.

This commit is contained in:
alwayscompiling
2022-12-01 22:58:39 -05:00
parent 58e616ea47
commit 02145ba244
11 changed files with 49 additions and 28 deletions
+22
View File
@@ -0,0 +1,22 @@
"""
Simple file to set up the sqlalchemy connection to database.
"""
from sqlalchemy import create_engine
from sqlalchemy.ext.automap import automap_base
from sqlalchemy.orm import Session
import config
# connect with sql alchemy and autoload schema
url = f"mysql://{config.SQL_USER}:{config.SQL_PASS}@{config.SQL_HOST}/{config.SQL_DB}"
engine = create_engine(url)
connection = engine.connect()
Base = automap_base()
Base.prepare(autoload_with=engine)
session = Session(engine)
# define the classes
Guild = Base.classes.Guilds
CategoryGroup = Base.classes.CategoryGroups
Category = Base.classes.Categories
Score = Base.classes.Scores
+2 -2
View File
@@ -10,7 +10,8 @@ import pandas as pd
from sqlalchemy import distinct, select
from sqlalchemy.orm import aliased
from highscores import Category, CategoryGroup, Guild, Score, engine, session
# pylint: disable=import-error
from utilities.sql_alchemy_connection import Category, CategoryGroup, Guild, Score, engine, session
MAX_LINE_LENGTH = 142
@@ -336,7 +337,6 @@ async def submit_score(
group = session.scalar(stmt)
# edit message
print(f"Editting message {group.MessageId}")
channel = interaction.guild.get_channel(group.ChannelId)
error_response = "Registered Highscores channel does not exist or was never registered."