def __exit__( self, exc_type: Type[BaseException], exc_val: BaseException, exc_tb: TracebackType, ) -> None: try: if exc_val: self.c.rollback() raise exc_val elif not self.commit: self.c.rollback() else: self.c.commit() except psycopg2.InterfaceError as e: self.c.close(timeout=0) raise InterfaceError(e) except psycopg2.DataError as e: raise DataError(e) except psycopg2.OperationalError as e: raise OperationalError(e) except psycopg2.IntegrityError as e: raise IntegrityError(e) except psycopg2.InternalError as e: raise InternalError(e) except psycopg2.ProgrammingError as e: raise ProgrammingError(e) except psycopg2.NotSupportedError as e: raise NotSupportedError(e) except psycopg2.DatabaseError as e: raise DatabaseError(e) except psycopg2.Error as e: raise PersistenceError(e) finally: self.c.is_idle.set()
def __exit__( self, exc_type: Type[BaseException], exc_val: BaseException, exc_tb: TracebackType, ) -> None: try: if exc_val: # Roll back all changes # if an exception occurs. self.connection.rollback() raise exc_val elif not self.commit: self.connection.rollback() else: self.connection.commit() except sqlite3.InterfaceError as e: raise InterfaceError(e) from e except sqlite3.DataError as e: raise DataError(e) from e except sqlite3.OperationalError as e: raise OperationalError(e) from e except sqlite3.IntegrityError as e: raise IntegrityError(e) from e except sqlite3.InternalError as e: raise InternalError(e) from e except sqlite3.ProgrammingError as e: raise ProgrammingError(e) from e except sqlite3.NotSupportedError as e: raise NotSupportedError(e) from e except sqlite3.DatabaseError as e: raise DatabaseError(e) from e except sqlite3.Error as e: raise PersistenceError(e) from e
def rollback(self): if self.closed: raise PersistenceError("Closed")
def commit(self): if self.closed: raise PersistenceError("Closed")