Fixed small error in calling database connection

Made more database connections Asynchronous
pull/8/head
sgoudham 4 years ago
parent 6b868ac6a0
commit ee41ce03b7

@ -65,7 +65,7 @@ async def storage_modlog_for_guild(ctx, channelID, setup):
modlogs[str(ctx.guild.id)] = channelID modlogs[str(ctx.guild.id)] = channelID
# Setup pool # Setup pool
pool = await db.connection2(db.loop) pool = await db.connection(db.loop)
# Setup up pool connection and cursor # Setup up pool connection and cursor
async with pool.acquire() as conn: async with pool.acquire() as conn:
@ -139,15 +139,19 @@ cached_prefixes = {}
async def storage_prefix_for_guild(ctx, prefix): async def storage_prefix_for_guild(ctx, prefix):
cached_prefixes[str(ctx.guild.id)] = prefix cached_prefixes[str(ctx.guild.id)] = prefix
with db.connection() as connection: # Setup pool
pool = await db.connection(db.loop)
# Setup up pool connection and cursor
async with pool.acquire() as conn:
async with conn.cursor() as cur:
# Update the existing prefix within the database # Update the existing prefix within the database
update_query = """UPDATE guilds SET prefix = (?) WHERE guildID = (?)""" update_query = """UPDATE guilds SET prefix = (%s) WHERE guildID = (%s)"""
update_vals = prefix, ctx.guild.id, update_vals = prefix, ctx.guild.id,
# Using the connection cursor
with closing(connection.cursor()) as cur:
# Execute the query # Execute the query
cur.execute(update_query, update_vals) await cur.execute(update_query, update_vals)
await conn.commit()
print(cur.rowcount, f"Guild prefix has been updated for guild {ctx.guild.name}") print(cur.rowcount, f"Guild prefix has been updated for guild {ctx.guild.name}")
# Let the user know that the guild prefix has been updated # Let the user know that the guild prefix has been updated

Loading…
Cancel
Save