Start testing with sqlmodel.
This commit is contained in:
@@ -135,3 +135,4 @@ deleted_backups/
|
|||||||
highscores_data/
|
highscores_data/
|
||||||
TODO.txt
|
TODO.txt
|
||||||
sql_tester.py
|
sql_tester.py
|
||||||
|
database.db
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
from sqlmodel import BigInteger, Column, Field, SQLModel, create_engine
|
||||||
|
|
||||||
|
|
||||||
|
class Guilds(SQLModel, table=True):
|
||||||
|
id: int = Field(sa_column=Column(BigInteger(), primary_key=True))
|
||||||
|
name: str = Field(max_length=95)
|
||||||
|
submission_channel: int = Field(sa_column=Column(BigInteger()))
|
||||||
|
verification_channel: int = Field(sa_column=Column(BigInteger()))
|
||||||
|
active: bool = Field(default=True)
|
||||||
|
|
||||||
|
|
||||||
|
url = "sqlite:///database.db"
|
||||||
|
engine = create_engine(url)
|
||||||
|
SQLModel.metadata.create_all(engine)
|
||||||
@@ -1,18 +1,32 @@
|
|||||||
"""Simple file to set up the sqlalchemy connection to database."""
|
"""Simple file to set up the sqlalchemy connection to database."""
|
||||||
|
|
||||||
from sqlalchemy import create_engine
|
# from sqlalchemy import create_engine
|
||||||
from sqlalchemy.ext.automap import automap_base
|
# from sqlalchemy.ext.automap import automap_base
|
||||||
|
from sqlmodel import BigInteger, Column, Field, SQLModel, create_engine
|
||||||
from utilities import config
|
from utilities import config
|
||||||
|
|
||||||
# connect with sql alchemy and autoload schema
|
|
||||||
url = f"mysql+pymysql://{config.SQL_USER}:{config.SQL_PASS}@{config.SQL_HOST}/{config.SQL_DB}"
|
|
||||||
engine = create_engine(url)
|
|
||||||
Base = automap_base()
|
|
||||||
Base.prepare(autoload_with=engine)
|
|
||||||
|
|
||||||
# define the classes
|
class Guilds(SQLModel, table=True):
|
||||||
Category = Base.classes.Categories
|
id: int = Field(sa_column=Column(BigInteger(), primary_key=True))
|
||||||
CategoryGroup = Base.classes.CategoryGroups
|
name: str
|
||||||
Guild = Base.classes.Guilds
|
submission_channel: int = Field(sa_column=Column(BigInteger()))
|
||||||
Score = Base.classes.Scores
|
verification_channel: int = Field(sa_column=Column(BigInteger()))
|
||||||
Submission = Base.classes.Submissions
|
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
|
||||||
|
|||||||
+2
-3
@@ -1,6 +1,4 @@
|
|||||||
"""
|
"""Loads environment variables for use in bot."""
|
||||||
Loads environment variables for use in bot.
|
|
||||||
"""
|
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
@@ -15,3 +13,4 @@ SQL_DB = os.getenv("SQL_DB", "")
|
|||||||
SQL_HOST = os.getenv("SQL_HOST", "")
|
SQL_HOST = os.getenv("SQL_HOST", "")
|
||||||
SQL_PASS = os.getenv("SQL_PASS", "")
|
SQL_PASS = os.getenv("SQL_PASS", "")
|
||||||
SQL_USER = os.getenv("SQL_USER", "")
|
SQL_USER = os.getenv("SQL_USER", "")
|
||||||
|
ENVIRONMENT: str = os.getenv("ENVIRONMENT", "prod")
|
||||||
|
|||||||
Reference in New Issue
Block a user