Node object¶
-
class
Node
(transaction, id)¶ Representation of a tree node and entrypoint for local tree operations.
It’s a thin wrapper around the underlaying core functions. It does not contain any data besides the database ID and must therefore query the database every time the value of an attribute like
parent
has been requested. This decision has been made to avoid race conditions when working in concurrent or distributed environments, but comes at the cost of slower runtime execution speeds. If this becomes a problem for you, grab the the correspondinglibtree.core.node_data.NodeData
object vialibtree.node.Node.node_data
.This object is tightly coupled to a
libtree.transaction.Transaction
object. It behaves like a partial which passes a database cursor and node ID into everylibtree.core
function. It also has a few convenience features like attribute access via Python properties and shorter method names.Parameters: - transaction (Transaction) – Transaction object
- id (int) – Database node ID
-
__len__
()¶ Return amount of child nodes.
-
__eq__
(other)¶ Determine if this node is equal to
other
.
-
ancestors
¶ Get list of ancestor nodes.
-
children
¶ Get list of immediate child nodes.
-
delete
()¶ Delete node and its subtree.
-
descendants
¶ Get list of descendant nodes.
-
get_child_at_position
(position)¶ Get child node at certain position.
Parameters: position (int) – Position to get the child node from
-
id
¶ Database ID
-
inherited_properties
¶ Get inherited property dictionary.
-
insert_child
(properties=None, position=-1)¶ Create a child node and return it.
Parameters: - properties (dict) – Inheritable key/value pairs (see Property functions)
- position (int) – Position in between siblings. If 0, the node will be inserted at the beginning of the parents children. If -1, the node will be inserted the the end of the parents children.
-
move
(target, position=-1)¶ Move node and its subtree from its current to another parent node. Raises
ValueError
iftarget
is inside this nodes’ subtree.Parameters: - target (Node) – New parent node
- position (int) – Position in between siblings. If 0, the node will be inserted at the beginning of the parents children. If -1, the node will be inserted the the end of the parents children.
-
node_data
¶ Get a
libtree.core.node_data.NodeData
object for current node ID from database.
-
parent
¶ Get parent node.
-
position
¶ Get position in between sibling nodes.
-
properties
¶ Get property dictionary.
-
set_position
(new_position)¶ Set position.
Parameters: position (int) – Position in between siblings. If 0, the node will be inserted at the beginning of the parents children. If -1, the node will be inserted the the end of the parents children.
-
set_properties
(properties)¶ Set properties.
Parameters: properties (dict) – Property dictionary