From 31ac939f58bf7b6d353ced995ca395376203b25f Mon Sep 17 00:00:00 2001 From: Alexander Kabui Date: Mon, 12 Apr 2021 09:54:12 +0300 Subject: Integrate correlation API - add new api for gn2-gn3 sample r integration - delete map for sample list to values - add db util file - add python msql-client dependency - add db for fetching lit correlation results - add unittests for db utils - add tests for db_utils - modify api for fetching lit correlation results - refactor Mock Database Connector and unittests - add sql url parser - add SQL URI env variable - refactor code for db utils - modify return data for lit correlation - refactor tissue correlation endpoint - replace db_instance with conn--- gn3/db_utils.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 gn3/db_utils.py (limited to 'gn3/db_utils.py') 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 -- cgit v1.2.3