Advertisement
idanab

Untitled

Oct 19th, 2016
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.43 KB | None | 0 0
  1. import logging
  2. import psycopg2 as psycopg2
  3. import pprint
  4. import pyodbc as pyodbc
  5. import traceback
  6. from psycopg2.extras import LoggingConnection
  7.  
  8. dev= True
  9. ip_postgres_db='localhost'
  10.  
  11. class ConnectionObj(object):
  12. @staticmethod
  13. def get_mdclone_cursor():
  14. "Establish connection to DB"
  15. try:
  16. conn = psycopg2.connect(connect_timeout=0, database="mdclone", user="postgres", password="Ppp@24680", host="{host_val}".format(host_val=ip_postgres_db), port="5432")
  17. return conn, conn.cursor()
  18. except:
  19. traceback.print_exc()
  20. return "Problem while trying to connect to DB"
  21.  
  22. @staticmethod
  23. def get_patient_events_cursor():
  24. "Establish connection to DB"
  25. try:
  26. conn = psycopg2.connect(connect_timeout=0, database="PatientEvents", user="postgres", password="Ppp@24680", host="{host_val}".format(host_val=ip_postgres_db), port="5432")
  27. return conn, conn.cursor()
  28. except:
  29. traceback.print_exc()
  30. return "Problem while trying to connect to DB"
  31.  
  32. @staticmethod
  33. def get_pyodbc_datalake_cursor():
  34. try:
  35. connection = pyodbc.connect('DSN=Impala32', autocommit=True, readonly="True") #Impala32 is a driver that was built in ODBC Data Source Administrator (32-bit)
  36. return connection,connection.cursor()
  37. except:
  38. traceback.print_exc()
  39. return "Problem while trying to connect to DB"
  40.  
  41. @staticmethod
  42. def get_lifeflux_cursor(withLogging=False):
  43. if not withLogging:
  44. # ""Establish connection to DB"
  45. try:
  46. conn = psycopg2.connect(connect_timeout=0, database="lifeflux", user="postgres", password="Ppp@24680",
  47. host="{host_val}".format(host_val=ip_postgres_db),
  48. port="5432")
  49. return conn, conn.cursor()
  50. except:
  51. traceback.print_exc()
  52. return "Problem while trying to connect to DB"
  53. else:
  54. "Establish connection to DB"
  55. try:
  56. # conn = psycopg2.connect(database="lifeflux", user="postgres", password="Ppp@24680", host="13.92.125.237",
  57. # port="5432")
  58. logging.basicConfig(level=logging.DEBUG)
  59. logger = logging.getLogger(__name__)
  60. db_settings = {
  61. "user": "postgres",
  62. "password": "Ppp@24680",
  63. "host":"{host_val}".format(host_val=ip_postgres_db),
  64. "database": "lifeflux",
  65. "connect_timeout": 0
  66. }
  67. conn = psycopg2.connect(connection_factory=LoggingConnection, **db_settings)
  68. conn.initialize(logger)
  69. return conn, conn.cursor()
  70. except:
  71. traceback.print_exc()
  72. return "Problem while trying to connect to DB"
  73.  
  74. @staticmethod
  75. def get_customdb_cursor():
  76. "Establish connection to DB"
  77. try:
  78. 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")
  79. return conn,conn.cursor()
  80. except:
  81. print("Problem while trying to connect to DB")
  82. traceback.print_exc()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement