View Source CTE.Adapter behaviour (Closure Table v1.1.2)

Specification of the Closure Table implementation.

Most of the functions implementing the CTE.Adapter behavior, 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

Link to this section Summary

Callbacks

Retrieve the ancestors of a node

Delete a leaf or a subtree. hĕdzˈŭpˈ: read the docs of the implementation, in case the implementation has specific side effects

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

Link to this section Types

Link to this section Callbacks

Link to this callback

ancestors(pid, descendant, options)

View Source
@callback ancestors(pid(), descendant :: any(), options()) ::
  {:ok, CTE.nodes()} | {:error, any()}

Retrieve the ancestors of a node

@callback delete(pid(), leaf :: any()) :: :ok | {:error, any()}

Delete a leaf or a subtree. hĕdzˈŭpˈ: read the docs of the implementation, in case the implementation has specific side effects

Link to this callback

delete(pid, leaf, options)

View Source
@callback delete(pid(), leaf :: any(), options()) :: :ok | {:error, any()}
Link to this callback

descendants(pid, ancestor, options)

View Source
@callback descendants(pid(), ancestor :: any(), options()) ::
  {:ok, CTE.nodes()} | {:error, any()}

Retrieve the descendants of a node

Link to this callback

insert(pid, leaf, ancestor, options)

View Source
@callback insert(pid(), leaf :: any(), ancestor :: any(), options()) ::
  {:ok, CTE.t()} | {:error, any()}

Insert a node under an existing ancestor

Link to this callback

move(pid, leaf, ancestor, options)

View Source
@callback move(pid(), leaf :: any(), ancestor :: any(), options()) ::
  :ok | {:error, any()}

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 callback

tree(pid, leaf, options)

View Source
@callback tree(pid(), leaf :: any(), options()) :: {:ok, CTE.nodes()} | {:error, any()}

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