def check_closed(function):
    """Decorator that checks if connection/cursor is closed."""

    def g(self, *args, **kwargs):
        if self.closed:
            raise Exception(f"{self.__class__.__name__} already closed")
        return function(self, *args, **kwargs)

    return g