Loading src/common/database.py +2 −24 Original line number Diff line number Diff line Loading @@ -6,12 +6,12 @@ PostgreSQL database. However, the connection paramater may be specified to open any type of connection through implementation of this abstract class. """ import traceback from abc import ABC, abstractmethod from abc import ABCMeta, abstractmethod from common.logz import create_logger from common.env import check_environment as ce class Database(ABC): class Database(ABCMeta): """ Provides an abstract class for connecting to a database using environmental variables. Loading Loading @@ -135,28 +135,6 @@ class Database(ABC): # If one or both connection and cursor are missing, return False return False def return_as_pandas(self, query): """ return a query as a pandas dataframe """ self.logger.info(f'Returning {query} as pandas') def make_pd_frame(query): dfq = self._cursor.execute(query) if dfq is None: print('unable to fetch data for query: %s' % query) return dfq df = pd.DataFrame(dfq.fetchall()) df.columns = dfq.keys() return df if self.is_open(): results = make_pd_frame(query) else: self.logger.warning('DB is not open, consider using "with"') self.open() results = make_pd_frame(query) self.close() return results def override_connection(self, connection): """Override the default connection, useful for using other connections than `psycopg2` for downstream development. Loading Loading
src/common/database.py +2 −24 Original line number Diff line number Diff line Loading @@ -6,12 +6,12 @@ PostgreSQL database. However, the connection paramater may be specified to open any type of connection through implementation of this abstract class. """ import traceback from abc import ABC, abstractmethod from abc import ABCMeta, abstractmethod from common.logz import create_logger from common.env import check_environment as ce class Database(ABC): class Database(ABCMeta): """ Provides an abstract class for connecting to a database using environmental variables. Loading Loading @@ -135,28 +135,6 @@ class Database(ABC): # If one or both connection and cursor are missing, return False return False def return_as_pandas(self, query): """ return a query as a pandas dataframe """ self.logger.info(f'Returning {query} as pandas') def make_pd_frame(query): dfq = self._cursor.execute(query) if dfq is None: print('unable to fetch data for query: %s' % query) return dfq df = pd.DataFrame(dfq.fetchall()) df.columns = dfq.keys() return df if self.is_open(): results = make_pd_frame(query) else: self.logger.warning('DB is not open, consider using "with"') self.open() results = make_pd_frame(query) self.close() return results def override_connection(self, connection): """Override the default connection, useful for using other connections than `psycopg2` for downstream development. Loading