Skip to content
Snippets Groups Projects
Commit ecf202a1 authored by Nicolas Barthes's avatar Nicolas Barthes
Browse files

added Class_Mod/SQL_connect.py to connect to SQL database

parent 828f69c0
No related branches found
No related tags found
No related merge requests found
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()
......@@ -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
......@@ -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
......
{
"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"
}
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment