aboutsummaryrefslogtreecommitdiff
path: root/gn3/db_utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'gn3/db_utils.py')
-rw-r--r--gn3/db_utils.py19
1 files changed, 12 insertions, 7 deletions
diff --git a/gn3/db_utils.py b/gn3/db_utils.py
index 3b72d28..2f08e1b 100644
--- a/gn3/db_utils.py
+++ b/gn3/db_utils.py
@@ -5,16 +5,21 @@ import MySQLdb as mdb
from gn3.settings import SQL_URI
-def parse_db_url() -> Tuple:
+def parse_db_url(db_uri: str) -> 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:])
+ parsed_db = urlparse(db_uri)
+ return (parsed_db.hostname, parsed_db.username, parsed_db.password,
+ parsed_db.path[1:], parsed_db.port)
-def database_connector() -> mdb.Connection:
+def database_connector(db_uri: str = SQL_URI) -> mdb.Connection:
"""function to create db connector"""
- host, user, passwd, db_name = parse_db_url()
- return mdb.connect(host, user, passwd, db_name)
+ return mdb.connect(**{
+ key: val for key, val in
+ dict(zip(
+ ("host", "user", "passwd", "db", "port"),
+ parse_db_url(db_uri))).items()
+ if bool(val)
+ })