aboutsummaryrefslogtreecommitdiff
path: root/qc_app
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2022-07-13 01:19:57 +0300
committerFrederick Muriuki Muriithi2022-07-19 04:59:59 +0300
commit0410f6e90b80d4aa8427ea3c398fe70e1977043c (patch)
tree8c3ee5aa7a33239f60e2321c5c4f1fab54f8cec2 /qc_app
parentee44431de6cf860fe89e796eab2bb0d555d90105 (diff)
downloadgn-uploader-0410f6e90b80d4aa8427ea3c398fe70e1977043c.tar.gz
Add missing db_utils module
Diffstat (limited to 'qc_app')
-rw-r--r--qc_app/db_utils.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/qc_app/db_utils.py b/qc_app/db_utils.py
new file mode 100644
index 0000000..95b0057
--- /dev/null
+++ b/qc_app/db_utils.py
@@ -0,0 +1,20 @@
+"""module contains all db related stuff"""
+from typing import Tuple
+
+from urllib.parse import urlparse
+import MySQLdb as mdb
+from flask import current_app as app
+
+def parse_db_url() -> Tuple:
+ """
+ Parse SQL_URI configuration variable.
+ """
+ parsed_db = urlparse(app.config["SQL_URI"])
+ return (parsed_db.hostname, parsed_db.username,
+ parsed_db.password, parsed_db.path[1:])
+
+
+def database_connection() -> mdb.Connection:
+ """function to create db connector"""
+ host, user, passwd, db_name = parse_db_url()
+ return mdb.connect(host, user, passwd, db_name)