From eae345ed252c01e541d64c7e5b60b488d84268c6 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Tue, 8 Mar 2022 08:00:16 +0300 Subject: Create database connections within context managers Use the `with` context manager to open database connections, so as to ensure that those connections are closed once the call is completed. This hopefully avoids the 'too many connections' error --- gn3/db_utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'gn3/db_utils.py') diff --git a/gn3/db_utils.py b/gn3/db_utils.py index 7263705..3703cbb 100644 --- a/gn3/db_utils.py +++ b/gn3/db_utils.py @@ -14,10 +14,10 @@ def parse_db_url() -> Tuple: parsed_db.password, parsed_db.path[1:]) -def database_connector() -> Tuple: +def database_connector() -> mdb.Connection: """function to create db connector""" host, user, passwd, db_name = parse_db_url() conn = mdb.connect(host, user, passwd, db_name) cursor = conn.cursor() - return (conn, cursor) + return conn -- cgit v1.2.3