blob: 95b0057be92dd1a790d910c247e5c6690c699c33 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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)
|