diff options
author | John Nduli | 2024-06-12 11:23:47 +0300 |
---|---|---|
committer | BonfaceKilz | 2024-06-12 11:49:43 +0300 |
commit | 2663ed5ae406c0a99a0a610f08f4866d46107eca (patch) | |
tree | 77e47f4e8c5d77576feac619dbdfde13c9a28c1b /gn3 | |
parent | ae46efda7ec0e42997bec93a1ffacc29366d190b (diff) | |
download | genenetwork3-2663ed5ae406c0a99a0a610f08f4866d46107eca.tar.gz |
refactor: add db_utils global logger that will be the default
Diffstat (limited to 'gn3')
-rw-r--r-- | gn3/db_utils.py | 9 |
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, |