Files
agon/database_setup/sql_data_classes.py
T

33 lines
1.1 KiB
Python

"""Simple file to set up the sqlalchemy connection to database."""
# from sqlalchemy import create_engine
# from sqlalchemy.ext.automap import automap_base
from sqlmodel import BigInteger, Column, Field, SQLModel, create_engine
from utilities import config
class Guilds(SQLModel, table=True):
id: int = Field(sa_column=Column(BigInteger(), primary_key=True))
name: str
submission_channel: int = Field(sa_column=Column(BigInteger()))
verification_channel: int = Field(sa_column=Column(BigInteger()))
active: bool = Field(default=True)
# connect with sql alchemy and autoload schema
if config.ENVIRONMENT == "prod":
url = f"mysql+pymysql://{config.SQL_USER}:{config.SQL_PASS}@{config.SQL_HOST}/{config.SQL_DB}"
else:
url = "sqlite:///database.db"
engine = create_engine(url)
SQLModel.metadata.create_all(engine)
# Base = automap_base()
# Base.prepare(autoload_with=engine)
# # define the classes
# Category = Base.classes.Categories
# CategoryGroup = Base.classes.CategoryGroups
# Guild = Base.classes.Guilds
# Score = Base.classes.Scores
# Submission = Base.classes.Submissions