The two channel ids need to be NULL by default, don't know them on object creation.
41 lines
1.3 KiB
Python
41 lines
1.3 KiB
Python
import os
|
|
|
|
from dotenv import load_dotenv
|
|
from sqlmodel import Session, SQLModel, create_engine, select
|
|
|
|
from models import CategoryGroup, Guild
|
|
|
|
load_dotenv()
|
|
|
|
SQL_DB = os.getenv("SQL_DB", "")
|
|
SQL_HOST = os.getenv("SQL_HOST", "")
|
|
SQL_PASS = os.getenv("SQL_PASS", "")
|
|
SQL_USER = os.getenv("SQL_USER", "")
|
|
|
|
url = "sqlite:///database.db"
|
|
# url = f"mysql+pymysql://{SQL_USER}:{SQL_PASS}@{SQL_HOST}/{SQL_DB}"
|
|
engine = create_engine(url)
|
|
SQLModel.metadata.create_all(engine)
|
|
|
|
with Session(engine) as session:
|
|
guild = Guild(id=1, name="test guild")
|
|
session.add(guild)
|
|
group1 = CategoryGroup(name="group1", channel_id=1, guild_id=1, message_id=1)
|
|
group2 = CategoryGroup(name="group2", channel_id=2, guild_id=1, message_id=2)
|
|
session.add(group1)
|
|
session.add(group2)
|
|
session.commit()
|
|
|
|
# anotherone = Guild(id=2, name="test guild 2", submission_channel=1, verification_channel=2)
|
|
# session.add(anotherone)
|
|
# group1 = CategoryGroup(name="group1", channel_id=1, guild_id=2, message_id=1)
|
|
# group2 = CategoryGroup(name="group2", channel_id=2, guild_id=2, message_id=2)
|
|
# session.add(group1)
|
|
# session.add(group2)
|
|
# session.commit()
|
|
|
|
stmt = select(Guild).where(Guild.name == "Dakiny")
|
|
guild = session.scalar(stmt)
|
|
|
|
print(guild.category_groups)
|