Connectors¶
- class hermes.connectors.PostgresConnector(dsn, cursor_factory=<class 'psycopg2.extras.DictCursor'>)¶
Postgres-talking connection wrapper. A thin wrapper to encapsulate the complexity of creating, re-creating, and disconnecting from a Postgres database.
Creating a PostgresConnector is done like so:
from psycopg2.extras import DictCursor # Define a Postgres DSN dictionary dsn = {'database': 'example_db', 'host': '127.0.0.1', 'port': 5432, 'user': 'example', 'password': 'example'} cursor_factory = DictCursor # Pass the DSN to the PostgresConnector's constructor connector = PostgresConnector(dsn, cursor_factory=cursor_factory)
Parameters: - dsn – A Postgres-compatible DSN dictionary
- cursor_factory – A callable cursor subclass
- disconnect()¶
Disconnects from the Postgres instance unless it is already disconnected.
- is_server_master()¶
Enquires as to whether this server is a master or a slave.
Returns: A boolean indicating whether the server is master.
- pg_connection¶
Connects to the Postgres host, if a connection does not exist or is closed, using the the DSN provided in the constructor.
Automatically sets connection isolation level to AUTOCOMMIT.
Returns: A connection object