Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import logging
- import psycopg2 as psycopg2
- import pprint
- import pyodbc as pyodbc
- import traceback
- from psycopg2.extras import LoggingConnection
- dev= True
- ip_postgres_db='localhost'
- class ConnectionObj(object):
- @staticmethod
- def get_mdclone_cursor():
- "Establish connection to DB"
- try:
- conn = psycopg2.connect(connect_timeout=0, database="mdclone", user="postgres", password="Ppp@24680", host="{host_val}".format(host_val=ip_postgres_db), port="5432")
- return conn, conn.cursor()
- except:
- traceback.print_exc()
- return "Problem while trying to connect to DB"
- @staticmethod
- def get_patient_events_cursor():
- "Establish connection to DB"
- try:
- conn = psycopg2.connect(connect_timeout=0, database="PatientEvents", user="postgres", password="Ppp@24680", host="{host_val}".format(host_val=ip_postgres_db), port="5432")
- return conn, conn.cursor()
- except:
- traceback.print_exc()
- return "Problem while trying to connect to DB"
- @staticmethod
- def get_pyodbc_datalake_cursor():
- try:
- connection = pyodbc.connect('DSN=Impala32', autocommit=True, readonly="True") #Impala32 is a driver that was built in ODBC Data Source Administrator (32-bit)
- return connection,connection.cursor()
- except:
- traceback.print_exc()
- return "Problem while trying to connect to DB"
- @staticmethod
- def get_lifeflux_cursor(withLogging=False):
- if not withLogging:
- # ""Establish connection to DB"
- try:
- conn = psycopg2.connect(connect_timeout=0, database="lifeflux", user="postgres", password="Ppp@24680",
- host="{host_val}".format(host_val=ip_postgres_db),
- port="5432")
- return conn, conn.cursor()
- except:
- traceback.print_exc()
- return "Problem while trying to connect to DB"
- else:
- "Establish connection to DB"
- try:
- # conn = psycopg2.connect(database="lifeflux", user="postgres", password="Ppp@24680", host="13.92.125.237",
- # port="5432")
- logging.basicConfig(level=logging.DEBUG)
- logger = logging.getLogger(__name__)
- db_settings = {
- "user": "postgres",
- "password": "Ppp@24680",
- "host":"{host_val}".format(host_val=ip_postgres_db),
- "database": "lifeflux",
- "connect_timeout": 0
- }
- conn = psycopg2.connect(connection_factory=LoggingConnection, **db_settings)
- conn.initialize(logger)
- return conn, conn.cursor()
- except:
- traceback.print_exc()
- return "Problem while trying to connect to DB"
- @staticmethod
- def get_customdb_cursor():
- "Establish connection to DB"
- try:
- conn = psycopg2.connect(connect_timeout=0, database="winnie_db", user="postgres", password="Ppp@24680", host="{host_val}".format(host_val=ip_postgres_db), port="5432")
- return conn,conn.cursor()
- except:
- print("Problem while trying to connect to DB")
- traceback.print_exc()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement