From 7e9a8aeaab78c5863317d1fa6be9cd145df560a8 Mon Sep 17 00:00:00 2001 From: sgoudham Date: Mon, 27 Jul 2020 07:03:21 +0100 Subject: [PATCH] Trying to get asynchronous database connections working --- main.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/main.py b/main.py index f7f3e37b..b85c51bf 100644 --- a/main.py +++ b/main.py @@ -157,17 +157,17 @@ async def _help(ctx, *, command: Optional[str] = None): async def reload_db(ctx): pool = await db.connection2(db.loop) - with db.connection() as conn: - with closing(conn.cursor()) as cursor: + async with pool.acquire() as conn: + async with conn.cursor() as cur: # Define the insert statement that will insert the user's information insert = "INSERT IGNORE INTO members (guildID, discordID) VALUES " + ", ".join( map(lambda m: f"({ctx.guild.id}, {m.id})", ctx.guild.members)) try: # Execute the query - cursor.execute(insert) + await cur.execute(insert) except Exception as e: print(e) - print(cursor.rowcount, f"Record(s) inserted successfully into Members from {ctx.guild.name}") + print(cur.rowcount, f"Record(s) inserted successfully into Members from {ctx.guild.name}") @client.command(name="prefix", aliases=["Prefix"]) @@ -214,7 +214,7 @@ async def on_guild_join(guild): print(cursor.rowcount, f"Record inserted successfully into Guilds from {guild.name}") # Define the insert statement that will insert the user's information - insert = "INSERT INTO members (guildID, discordID) VALUES" + ", ".join( + insert = "INSERT IGNORE INTO members (guildID, discordID) VALUES" + ", ".join( map(lambda m: f"({guild.id}, {m.id})", guild.members)) with closing(conn.cursor()) as cursor: # Execute the query