aboutsummaryrefslogtreecommitdiff
path: root/gn3
diff options
context:
space:
mode:
Diffstat (limited to 'gn3')
-rw-r--r--gn3/db_utils.py9
1 files changed, 5 insertions, 4 deletions
diff --git a/gn3/db_utils.py b/gn3/db_utils.py
index e08caf0..19537d4 100644
--- a/gn3/db_utils.py
+++ b/gn3/db_utils.py
@@ -1,12 +1,15 @@
"""module contains all db related stuff"""
import contextlib
import logging
-from typing import Any, Iterator, Optional, Protocol, Tuple
+from typing import Any, Iterator, Protocol, Tuple
from urllib.parse import urlparse
import MySQLdb as mdb
import xapian
+LOGGER = logging.getLogger(__file__)
+
+
def parse_db_url(sql_uri: str) -> Tuple:
"""function to parse SQL_URI env variable note:there\
is a default value for SQL_URI so a tuple result is\
@@ -25,10 +28,8 @@ class Connection(Protocol):
@contextlib.contextmanager
-def database_connection(sql_uri: str, logger: Optional[logging.Logger] = None) -> Iterator[Connection]:
+def database_connection(sql_uri: str, logger: logging.Logger = LOGGER) -> Iterator[Connection]:
"""Connect to MySQL database."""
- if logger is None:
- logger = logging.getLogger(__file__)
host, user, passwd, db_name, port = parse_db_url(sql_uri)
connection = mdb.connect(db=db_name,
user=user,