You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ClinicalTrialsDataProcessing/data_mgmt_scripts/drugtools/env_setup.py

44 lines
1.2 KiB
Python

import pymysql
import psycopg2 as psyco
from psycopg2.sql import SQL
from dotenv import dotenv_values
env_path = "../containers/.env"
ENV = dotenv_values(env_path)
def mariadb_conn(**kwargs):
return pymysql.connect(
database=ENV["MYSQL_DB"]
,user=ENV["MYSQL_USER"]
,host=ENV["MYSQL_HOST"]
,port=int(ENV["MYSQL_PORT"])
,password=ENV["MYSQL_PASSWORD"]
,**kwargs
)
def postgres_conn(**kwargs):
return psyco.connect(
dbname=ENV["POSTGRES_DB"]
,user=ENV["POSTGRES_USER"]
,host=ENV["POSTGRES_HOST"]
,port=ENV["POSTGRES_PORT"]
,password=ENV["POSTGRES_PASSWORD"]
,**kwargs
)
def get_tables_of_interest():
return ENV["TABLES_OF_INTEREST"].split(",")
def postgres_table_delete_entries(schema,table):
with postgres_conn() as con:
with con.cursor() as curse:
delete_statement = SQL("delete from {schema}.{table}").format(
schema=Identifier(schema),
talbe=Identifier(table)
)
curse.execute(delete_statement)
con.commit()