View Source CTE.Ecto (Closure Table v2.0.5)

Most of the functions provided will accept the following options:

  • :limit, to limit the total number of nodes returned, when finding the ancestors or the descendants for nodes
  • :itself, accepting a boolean value. When true, the node used for finding its neighbors are returned as part of the results. Default: true
  • :nodes, accepting a boolean value. When true, the results are containing additional information about the nodes. Default: false

Summary

Functions

Retrieve the ancestors of a node

Delete a leaf or a subtree.

Retrieve the descendants of a node

Insert a node under an existing ancestor

Move a subtree from one location to another.

Calculate and return a "tree" structure containing the paths and the nodes under the given leaf/node

Functions

Link to this function

ancestors(descendant, opts, config)

View Source

Retrieve the ancestors of a node

Link to this function

delete(leaf, opts, config)

View Source

Delete a leaf or a subtree.

To delete a leaf node set the limit option to: 1, and in this particular case all the nodes that reference the leaf will be assigned to the leaf's immediate ancestor

If limit is 0, then the leaf and its descendants will be deleted

Link to this function

descendants(ancestor, opts, config)

View Source

Retrieve the descendants of a node

Link to this function

insert(leaf, ancestor, opts, config)

View Source

Insert a node under an existing ancestor

Link to this function

move(leaf, ancestor, opts, config)

View Source

Move a subtree from one location to another.

First, the subtree and its descendants are disconnected from its ancestors. And second, the subtree is inserted under the new parent (ancestor) and the subtree, including its descendants, is declared as descendants of all the new ancestors.

Link to this function

tree(leaf, opts, config)

View Source

Calculate and return a "tree" structure containing the paths and the nodes under the given leaf/node