diff options
Diffstat (limited to 'qc_app/db_utils.py')
-rw-r--r-- | qc_app/db_utils.py | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/qc_app/db_utils.py b/qc_app/db_utils.py index 95b0057..239f45c 100644 --- a/qc_app/db_utils.py +++ b/qc_app/db_utils.py @@ -1,20 +1,20 @@ """module contains all db related stuff""" -from typing import Tuple +from typing import Tuple, Optional from urllib.parse import urlparse import MySQLdb as mdb from flask import current_app as app -def parse_db_url() -> Tuple: +def parse_db_url(db_url) -> Tuple: """ Parse SQL_URI configuration variable. """ - parsed_db = urlparse(app.config["SQL_URI"]) + parsed_db = urlparse(db_url) return (parsed_db.hostname, parsed_db.username, parsed_db.password, parsed_db.path[1:]) -def database_connection() -> mdb.Connection: +def database_connection(db_url: Optional[str] = None) -> mdb.Connection: """function to create db connector""" - host, user, passwd, db_name = parse_db_url() + host, user, passwd, db_name = parse_db_url(db_url or app.config["SQL_URI"]) return mdb.connect(host, user, passwd, db_name) |