diff --git a/Class_Mod/SQL_connect.py b/Class_Mod/SQL_connect.py new file mode 100644 index 0000000000000000000000000000000000000000..fd29a6dc5eb92d354e67adab47760ae73d2e55d7 --- /dev/null +++ b/Class_Mod/SQL_connect.py @@ -0,0 +1,36 @@ +from Packages import pyodbc, json + +class SQL_Database(): + + def __init__(self): + + with open('../config/config.json', 'r') as fh: + config = json.load(fh) + + self.driver = config['DRIVER'] + self.server = config['SERVER'] + self.database = config['DATABASE'] + self.uid = config['UID'] + self.pwd = config['PWD'] + self.port = config['PORT'] + self.encrypt = config['ENCRYPT'] + + def connect(self): + connection = pyodbc.connect( + f'Driver={self.driver};' + f'Server={self.server};' + f'Database={self.database};' + f'uid={self.uid};' + f'pwd={self.pwd};' + f'port={self.port};' + f'Encrypt={self.encrypt};' + ) + return connection + +# How to connect to the db? +# con = SQL_Database().connect() +# quest = con.execute("SELECT table_schema || '.' || table_name FROM information_schema.tables WHERE table_type = 'BASE TABLE' AND table_schema NOT IN ('pg_catalog', 'information_schema');") +# row = quest.fetchone() +# print(row) +# quest.close() +# con.close() diff --git a/Packages.py b/Packages.py index 7746b733a37f8e44a0ee8c6ad4a923ab8bdd40e6..19480ebde1529cc6a924579923b0e31f7473f2d1 100644 --- a/Packages.py +++ b/Packages.py @@ -41,5 +41,10 @@ from sklearn.metrics import pairwise_distances_argmin_min ## Web app construction import streamlit as st +# help on streamlit input https://docs.streamlit.io/library/api-reference/widgets + +#Library for connecting to SQL DB +import pyodbc +#Library for reading the config file, which is in JSON +import json -# help on streamlit input https://docs.streamlit.io/library/api-reference/widgets \ No newline at end of file diff --git a/README.md b/README.md index ad7e3cb6ac1a220ac4cd9d51ad75af935580ce06..1edf0f54ef393356556e0a87f77cc94840f214a9 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,9 @@ The process includes: - predictions - the PINARD package uses the model to predict chemical values for unknown samples. - + +If one wants to use data stored in a SQL database, the config file is in the config/ folder. + ## Installation This package is written in python. You can clone the repository: git clone https://src.koda.cnrs.fr/nicolas.barthes.5/nirs_workflow.git diff --git a/config/config.json b/config/config.json new file mode 100644 index 0000000000000000000000000000000000000000..3f0bcef95cf5bda64e25792a23e6a568f8d6c04e --- /dev/null +++ b/config/config.json @@ -0,0 +1,9 @@ +{ + "DRIVER":"{PostgreSQL Unicode(x64)}", + "DATABASE":"NIRS_Workflow", + "UID":"NIRS_Workflow", + "PWD":"{lE_mOt%dE_pAsSe%NIRS!!2024}", + "SERVER":"10.8.1.225", + "PORT":"5432", + "ENCRYPT":"no" +} diff --git a/requirements.txt b/requirements.txt index 6afe88c1fd5989fb4ac89ea424b841aee57721aa..df3cab07c81e6f45bb151b4a2d16026afe67ba43 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,4 +5,5 @@ protobuf>=3.19.0 watchdog>=2.1.8 pinard>=1.0 julia>=0.6.2 -plotly>=5.20.0 \ No newline at end of file +plotly>=5.20.0 +pyodbc>=5.1.0 \ No newline at end of file