Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Begin work on switching out for sqlalchemy #15

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"python.venvPath": "venv"
}
20 changes: 0 additions & 20 deletions tgcommon/tgcommon/models.py

This file was deleted.

Empty file.
2 changes: 1 addition & 1 deletion tgcommon/tgcommon/models/tgschema.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@
discord_links = Table("discord_links", metadata,
Column("id", INTEGER(11, unsigned = True), nullable = False, autoincrement = True),
Column("ckey", VARCHAR(32), nullable = False),
Column("discord_id", BIGINT(20), nullable = TRUE, default= None),
Column("discord_id", BIGINT(20), nullable = True, default= None),
Column("timestamp", DATETIME(), nullable = False),
Column("one_time_token", VARCHAR(100), nullable=False),
Column("valid", BOOLEAN(), nullable=False, default=False),
Expand Down
19 changes: 17 additions & 2 deletions tgdb/tgdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
from redbot.core.utils.chat_formatting import pagify, box, humanize_list, warning
from redbot.core.utils.menus import menu, DEFAULT_CONTROLS

from tgcommon.models import DiscordLink
from tgcommon.models import tgschema
from aiomysql.sa import create_engine


__version__ = "1.0.0"
__author__ = "oranges"
Expand All @@ -30,6 +32,9 @@ class TGDB(BaseCog):
def __init__(self, bot):
self.bot = bot
self.config = Config.get_conf(self, identifier=672261474290237490, force_registration=True)
## Stores all our configured database pools (if you use this bot for multiple servers)
## They're indexed by a config key
self.database_pools = dict()
self.visible_config = ["mysql_host", "mysql_port", "mysql_user", "mysql_db", "mysql_prefix",
"min_living_minutes", "verified_role"]

Expand Down Expand Up @@ -188,6 +193,16 @@ async def current(self, ctx):
embed.add_field(name=f"{k}:",value="`redacted`",inline=False)
await ctx.send(embed=embed)

@checks.mod_or_permissions(administrator=True)
@commands.command()
async def test(self, ctx):
"""
Gets the current settings for the notes database
"""
cur = await self.pool.acquire()
res = await cur.execute(tgschema.discord_links.select())
for row in (await res.fetchall()):
print(row.id, row.one_time_token)

async def update_discord_link(self, ctx, one_time_token: str, user_discord_snowflake: str):
"""
Expand Down Expand Up @@ -334,7 +349,7 @@ async def reconnect_to_db(self, db, db_host, db_port, db_user, db_pass):
await self.pool.wait_closed()

# Establish a connection with the database and pull the relevant data, recycle them every 300 seconds
self.pool = await aiomysql.create_pool(host=db_host,port=db_port,db=db,user=db_user,password=db_pass, connect_timeout=5, pool_recycle=300)
self.pool = await aiomysql.sa.create_engine(host=db_host,port=db_port,db=db,user=db_user,password=db_pass, connect_timeout=5, pool_recycle=300)

async def query_database(self, ctx, query: str, parameters: list):
'''
Expand Down