diff --git a/main.py b/main.py index 514aa38..44eb4ae 100644 --- a/main.py +++ b/main.py @@ -13,10 +13,10 @@ async def on_connect(): print('Connected to Discord!') cursor = await mysql_login() - database = cursor.cursor() - database.execute("CREATE TABLE IF NOT EXISTS server (guild_id VARCHAR(255) PRIMARY KEY, server_ip TEXT NOT NULL)") - database.execute("CREATE TABLE IF NOT EXISTS blacklist (guild_id VARCHAR(21) PRIMARY KEY, reason TEXT NOT NULL)") - database.close() + database = await cursor.cursor() + await database.execute("CREATE TABLE IF NOT EXISTS server (guild_id VARCHAR(255) PRIMARY KEY, server_ip TEXT NOT NULL)") + await database.execute("CREATE TABLE IF NOT EXISTS blacklist (guild_id VARCHAR(21) PRIMARY KEY, reason TEXT NOT NULL)") + await database.close() @bot.listen() diff --git a/utilities/database.py b/utilities/database.py index 227a82f..898e776 100644 --- a/utilities/database.py +++ b/utilities/database.py @@ -1,4 +1,5 @@ -from mysql import connector as mysql +from mysql.connector.aio import connect + from utilities.data import get_data @@ -9,7 +10,7 @@ async def mysql_login(): """ database = get_data()['Database'] - return mysql.connect( + return await connect( host=database['Host'], user=database['User'], password=database['Password'], @@ -24,14 +25,15 @@ async def selector(query: str, variables: list) -> tuple: :return: The result of the query. If there is no result, it will return False. """ cursor = await mysql_login() - database = cursor.cursor() - database.execute(query, variables) + database = await cursor.cursor() + await database.execute(query, variables) try: - result = database.fetchall()[0] + result = await database.fetchall() + result = result[0] except IndexError: return () - database.close() - cursor.close() + await database.close() + await cursor.close() return result @@ -43,8 +45,8 @@ async def modifier(query: str, variables: list) -> None: :return: None """ cursor = await mysql_login() - database = cursor.cursor() - database.execute(query, variables) - cursor.commit() - database.close() - cursor.close() + database = await cursor.cursor() + await database.execute(query, variables) + await cursor.commit() + await database.close() + await cursor.close()