def get_ancestor_ids(cur, node):
    """
    Return an iterator that yields the ID of every element while
    traversing from ``node`` to the root node.

    :param node:
    :type node: Node or uuid4
    """
    sql = """
        SELECT
          ancestor
        FROM
          ancestors
        WHERE
          node=%s;
    """
    cur.execute(sql, (str(node),))
    for result in cur:
        yield str(result['ancestor'])
