diff options
author | Frederick Muriuki Muriithi | 2022-08-22 07:16:44 +0300 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2022-08-22 07:16:44 +0300 |
commit | 79c0e0933b4f252c3d76323891ae943a7ca6fd58 (patch) | |
tree | f791f9570e1ad764a2532244cf236e6a9b4c5a1c /gn3/db_utils.py | |
parent | 6db3b2af8fc09999996d3acc09890a06f179c669 (diff) | |
download | genenetwork3-79c0e0933b4f252c3d76323891ae943a7ca6fd58.tar.gz |
Use non-default MySQL port if present
By default, MySQL/Mariadb connects at port 3306, however, the configuration
variable `SQL_URI` could contain a different port. In that case, this commit
allows the system to connect to the non-default port.
Diffstat (limited to 'gn3/db_utils.py')
-rw-r--r-- | gn3/db_utils.py | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/gn3/db_utils.py b/gn3/db_utils.py index 3b72d28..4865131 100644 --- a/gn3/db_utils.py +++ b/gn3/db_utils.py @@ -10,11 +10,13 @@ def parse_db_url() -> Tuple: 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:]) + return ( + parsed_db.hostname, parsed_db.username, parsed_db.password, + parsed_db.path[1:], parsed_db.port) def database_connector() -> mdb.Connection: """function to create db connector""" - host, user, passwd, db_name = parse_db_url() - return mdb.connect(host, user, passwd, db_name) + host, user, passwd, db_name, db_port = parse_db_url() + + return mdb.connect(host, user, passwd, db_name, port=(db_port or 3306)) |