postgres_connector module¶
Postgres connectors are used to either connect to a Postgres database or write to a Postgres database.
- class postgres_connector.PostgresToDataFrameConnector(input_handler: libs.handler.postgres_handler.PostgresHandler, output_handler: libs.handler.json_handler.JsonHandler, log_handler: libs.log_handler.log_handler.LogHandler, write_logs: bool = True)¶
Bases:
libs.connector.generic_connector.GenericConnecter
The Connector handles an input postgres connection and outputs a copy of its DataFrame. This is especially useful in chaining operations using a DataFrameTo_________Connector.
- read()¶
Calls the Handler’s “execute” method and loads it into a dataframe.
- write()¶
The DataFrameHandler implements a null “execute” method because it does not handle any actual write operations. Instead, the write method returns a deep copy of the Connector instance dataframe.
- class postgres_connector.PostgresToExcelConnector(input_handler: libs.handler.postgres_handler.PostgresHandler, output_handler: libs.handler.excel_handler.ExcelHandler, log_handler: libs.log_handler.log_handler.LogHandler, write_logs: bool = True)¶
Bases:
libs.connector.generic_connector.GenericConnecter
The Connector handles an input postgres connection and outputs an excel filestream object.
- read()¶
Calls the Handler’s “execute” method and loads it into a dataframe.
- write(job_id: Optional[str] = None)¶
Returns a filestream object of an excel file
- class postgres_connector.PostgresToJsonConnector(input_handler: libs.handler.postgres_handler.PostgresHandler, output_handler: libs.handler.json_handler.JsonHandler, log_handler: libs.log_handler.log_handler.LogHandler, write_logs: bool = True)¶
Bases:
libs.connector.generic_connector.GenericConnecter
The write method returns a list of dictionaries that can then be serialized into JSON.
- read()¶
Calls the Handler’s “execute” method and loads it into a dataframe.
- transform(*funcs)¶
Accepts a handler and a number of functions that mutate a dataframe using another dataframe and returns a dictionary. The return dictionary must have a key of results and all keys in the dictionary must be arrays of records. Each function mutates the df attribute and the logger logs each of the steps.
Handlers of transform type do not take action on “refresh”.
- write()¶
The JsonHandler implements a null “execute” method because it does not handle any actual write operations. Instead, the write method returns the json data.
- class postgres_connector.PostgresToPostgresConnector(input_handler: libs.handler.postgres_handler.PostgresHandler, output_handler: libs.handler.postgres_handler.PostgresHandler, log_handler: libs.log_handler.log_handler.LogHandler, write_logs: bool = True)¶
Bases:
libs.connector.generic_connector.GenericConnecter
- read()¶
Calls the Handler’s “execute” method and loads it into a dataframe.
- write()¶