Python DB API 2¶
However imperfect may it be, it’s here to stay.
So enjoy!
-
class
satella.db.
transaction
(connection_or_getter, close_the_connection_after: bool = False, log_exception: bool = True)¶ A context manager for wrapping a transaction and getting a cursor from the Python DB API 2.
Use it as a context manager. commit and rollback will be automatically called for you.
Use like:
>>> with transaction(conn) as cur: >>> cur.execute('DROP DATABASE')
Leaving the context manager will automatically close the cursor for you.
Parameters: - connection_or_getter – the connection object to use, or a callable, that called with zero arguments will provide us with a connection
- close_the_connection_after – whether the connection should be closed after use
- log_exception – whether to log an exception if it happens