diff options
author | Frederick Muriuki Muriithi | 2022-04-14 12:04:18 +0300 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2022-04-14 12:04:18 +0300 |
commit | 1cbbe2d1da76d90014de089867b57eaa80f2f786 (patch) | |
tree | 09bedd95e2fda64edb50aac35743404a0d14f13a /wqflask | |
parent | e0eaa042da92b8cff3606a08adf783aeb1059188 (diff) | |
download | genenetwork2-1cbbe2d1da76d90014de089867b57eaa80f2f786.tar.gz |
Provide db port when present
Sometimes the system uses a port to connect to the database, rather
than a socket, so if the port is present, provide it as part of the
connection arguments.
Diffstat (limited to 'wqflask')
-rw-r--r-- | wqflask/wqflask/database.py | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/wqflask/wqflask/database.py b/wqflask/wqflask/database.py index afbb7923..f0ce0a77 100644 --- a/wqflask/wqflask/database.py +++ b/wqflask/wqflask/database.py @@ -33,10 +33,12 @@ def parse_db_url(sql_uri: str) -> Tuple: e.g. 'mysql://user:pass@host_name/db_name' """ 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_connection(): """Returns a database connection""" - host, user, passwd, db_name = parse_db_url(sql_uri()) - return MySQLdb.connect(db=db_name, user=user, passwd=passwd, host=host) + host, user, passwd, db_name, port = parse_db_url(sql_uri()) + return MySQLdb.connect( + db=db_name, user=user, passwd=passwd, host=host, port=port) |