postgres_handler module¶
Postgres handlers connect to a postgres database and manage the connection. The class reads and writes to the database using the “execute” method.
- class postgres_handler.PostgresHandler(db: Optional[str] = None, username: Optional[str] = None, password: Optional[str] = None, host: Optional[str] = None, port: Optional[int] = None, query: Optional[str] = None, schema: str = 'public', env_prefix: str = 'POSTGRES')¶
Bases:
libs.handler.base_handler.BaseDBHandler
- property columns: list¶
- property connection: psycopg2.extensions.connection¶
- property db: str¶
- property env_prefix: str¶
- execute(query: str, args: Optional[list] = None) object ¶
Executes the query attribute. It checks whether the passed query is of an allowed querytype as defined in the ALLOWED_QUERIES found in the “globals” module. Raises PostgresQueryError if the query is not allowed.
- property host: str¶
- property is_alive: bool¶
Returns whether the connection is “alive”, or open.
- classmethod load_param(param: str, env_name: str) str ¶
Used to load settings, such as conenction configuration, from the ENVIRONMENT if none are passed.
- property password: str¶
- property port: int¶
Raises ValueError if the port is not an integer.
- property query: str¶
- property schema: str¶
- property username: str¶