Query functions

get_ancestor_ids(cur, node)

Return an iterator that yields the ID of every element while traversing from node to the root node.

Parameters:node (Node or int) –
get_ancestors(cur, node, sort=True)

Return an iterator that yields a NodeData object of every element while traversing from node to the root node.

Parameters:
  • node (Node or int) –
  • sort (bool) – Start with closest node and end with root node. (default: True)
get_child_ids(cur, node)

Return an iterator that yields the ID of every immediate child.

Parameters:node (Node or int) –
get_children(cur, node)

Return an iterator that yields a NodeData object of every immediate child.

Parameters:node (Node or int) –
get_children_count(cur, node)

Get amount of immediate children.

Parameters:node (Node or int) – Node
get_descendant_ids(cur, node)

Return an iterator that yields a NodeData object of each element in the nodes subtree. Be careful when converting this iterator to an iterable (like list or set) because it could contain billions of objects.

Parameters:node (Node or int) –
get_descendants(cur, node)

Return an iterator that yields the ID of every element while traversing from node to the root node.

Parameters:node (Node or int) –
get_node(cur, id)

Return NodeData object for given id. Raises ValueError if ID doesn’t exist.

Parameters:id (int) – Database ID
get_node_at_position(cur, node, position)

Return node at position in the children of node.

Parameters:
  • node (Node or int) –
  • position (int) –
get_root_node(cur)

Return root node. Raise ValueError if root node doesn’t exist.

get_tree_size(cur)

Return the total amount of tree nodes.