From 1ba9dceb3306e8f4db7996130dbc40a356cf8b48 Mon Sep 17 00:00:00 2001
From: Raphael <raphael.sturgis@lis-lab.fr>
Date: Wed, 16 Feb 2022 17:01:28 +0100
Subject: [PATCH] added get_db_connection in config

---
 skais/utils/config.py | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/skais/utils/config.py b/skais/utils/config.py
index 5cfa2f0..c386a1f 100644
--- a/skais/utils/config.py
+++ b/skais/utils/config.py
@@ -8,6 +8,8 @@ import os
 from pathlib import Path
 from configparser import ConfigParser
 
+import psycopg2
+
 
 def get_config_file():
     """
@@ -58,6 +60,7 @@ def get_data_path():
                         .format(data_path, config_file))
     return data_path
 
+
 def get_db_config():
     """
     Read db config from user configuration file.
@@ -82,4 +85,14 @@ def get_db_config():
     if not dict:
         raise Exception('Invalid data path: {}. Update configuration file {}'
                         .format(dict, config_file))
-    return dict
\ No newline at end of file
+    return dict
+
+
+def get_db_connection():
+    db_config = get_db_config()
+    connection = psycopg2.connect(user=db_config['user'],
+                                  password=db_config['password'],
+                                  host=db_config['host'],
+                                  port=db_config['port'],
+                                  database=db_config['database'])
+    return connection
-- 
GitLab