Making connection more efficient with "with" statement

Adding Commentary
pull/4/head
sgoudham 4 years ago
parent 84f376465d
commit 03e8128610

@ -162,13 +162,10 @@ def SendMsgToModMail(self, msg, author):
return embed return embed
# Method to allow # Method to allow modmail to be logged into the database
def logModMail(ctx, anon, msg): def logModMail(ctx, anon, msg):
# Set up the connection to the database # With the database connection
conn = db.connection() with db.connection() as conn:
# With the connection
with conn:
# Make sure that mariaDB errors are handled properly # Make sure that mariaDB errors are handled properly
try: try:
if anon: if anon:

@ -37,11 +37,8 @@ async def on_message(message):
pass pass
else: else:
# Set up the connection to the database # Using connection to the database
conn = db.connection() with db.connection() as conn:
# With the connection
with conn:
# Make sure that mariaDB errors are handled properly # Make sure that mariaDB errors are handled properly
try: try:

Loading…
Cancel
Save