(self, database=None)
return conn
Connect to given database
Connect to given database
Connect to given database
def _connect(self, database=None):
        """
        Connect to given database
        """
        conn_args = {
            'host': self.config['host'],
            'user': self.config['user'],
            'password': self.config['password'],
            'port': self.config['port'],
            'sslmode': self.config['sslmode'],
        }

        if database:
            conn_args['database'] = database
        else:
            conn_args['database'] = 'postgres'

        # libpq will use ~/.pgpass only if no password supplied
        if self.config['password_provider'] == 'pgpass':
            del conn_args['password']

        try:
            conn = psycopg2.connect(**conn_args)
        except Exception as e:
            self.log.error(e)
            raise e

        # Avoid using transactions, set isolation level to autocommit
        conn.set_isolation_level(0)
        return conn
def _connect ( self , database = None ) : conn_args = { 'host' : self . config [ 'host' ] , 'user' : self . config [ 'user' ] , 'password' : self . config [ 'password' ] , 'port' : self . config [ 'port' ] , 'sslmode' : self . config [ 'sslmode' ] , } if database : conn_args [ 'database' ] = database else : conn_args [ 'database' ] = 'postgres' # libpq will use ~/.pgpass only if no password supplied if self . config [ 'password_provider' ] == 'pgpass' : del conn_args [ 'password' ] try : conn = psycopg2 . connect ( * * conn_args ) except Exception as e : self . log . error ( e ) raise e # Avoid using transactions, set isolation level to autocommit conn . set_isolation_level ( 0 ) return conn