Context manager for PG database connection
TODO: investigate connection pooling:
http://initd.org/psycopg/docs/pool.html
Definition at line 27 of file ody_migr_db_handler.py.
◆ __init__()
| def ody_migr_db_handler.PGSession.__init__ |
( |
|
self | ) |
|
◆ __enter__()
| def ody_migr_db_handler.PGSession.__enter__ |
( |
|
self | ) |
|
open database connection
Definition at line 38 of file ody_migr_db_handler.py.
39 """open database connection""" 41 self.conn = psycopg2.connect((
"host={} dbname={} " 42 "user={} password={}")
51 except psycopg2.OperationalError
as err:
52 raise SystemExit(
"Unable to connect!{}".format(err))
◆ __exit__()
| def ody_migr_db_handler.PGSession.__exit__ |
( |
|
self, |
|
|
|
exception_type, |
|
|
|
exception_value, |
|
|
|
_traceback |
|
) |
| |
close database connection
Definition at line 54 of file ody_migr_db_handler.py.
54 def __exit__(self, exception_type, exception_value, _traceback):
55 """close database connection""" 57 LOGGER.error(exception_value)
58 if self.conn
is not None:
The documentation for this class was generated from the following file: