aboutsummaryrefslogtreecommitdiff
path: root/gn3/db_utils.py
diff options
context:
space:
mode:
authorAlexander Kabui2021-04-12 16:53:48 +0300
committerAlexander Kabui2021-04-12 16:53:48 +0300
commit35f5ac0335f44923184ffe0f0a3380a9cf1859ef (patch)
tree8f1fcb15ace3574eb19bd0eafdc5b5bb0822ed09 /gn3/db_utils.py
parent8ce82f5b6cccc015c38a728864c63c026fe6a3a0 (diff)
parent31ac939f58bf7b6d353ced995ca395376203b25f (diff)
downloadgenenetwork3-35f5ac0335f44923184ffe0f0a3380a9cf1859ef.tar.gz
fix merge conflict
Diffstat (limited to 'gn3/db_utils.py')
-rw-r--r--gn3/db_utils.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/gn3/db_utils.py b/gn3/db_utils.py
new file mode 100644
index 0000000..34c5bf0
--- /dev/null
+++ b/gn3/db_utils.py
@@ -0,0 +1,24 @@
+"""module contains all db related stuff"""
+from typing import Tuple
+from urllib.parse import urlparse
+import MySQLdb as mdb # type: ignore
+from gn3.settings import SQL_URI
+
+
+def parse_db_url() -> Tuple:
+ """function to parse SQL_URI env variable note:there\
+ is a default value for SQL_URI so a tuple result is\
+ always expected"""
+ parsed_db = urlparse(SQL_URI)
+ return (parsed_db.hostname, parsed_db.username,
+ parsed_db.password, parsed_db.path[1:])
+
+
+def database_connector()->Tuple:
+ """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)
+ \ No newline at end of file