def current(cls, with_exception=True):
        """
        Returns the current database context.
        """
        if with_exception and len(cls.stack) == 0:
            raise NoContext()
        return cls.stack.top()