AncestryEx.Format (ancestry_ex v0.1.0)

Copy Markdown View Source

Encoding of the ancestry column.

Two formats are supported, both compatible with the Ruby ancestry gem:

  • :materialized_path2 (default, recommended) - roots store "/", a node whose ancestors are 1 and 2 stores "/1/2/". The column can be NOT NULL and descendant lookups are a single LIKE 'prefix%'.

  • :materialized_path - roots store NULL, a node whose ancestors are 1 and 2 stores "1/2". Use it when migrating a table managed by the gem's legacy default format.

Summary

Functions

Ancestry value of the children of a node with the given ancestry and id.

Depth of a node with the given ancestry value (roots have depth 0).

Builds an ancestry value from a list of ancestor ids, root first.

Splits an ancestry value into its id segments (as strings), root first.

Value stored in the ancestry column of a root node.

Returns true if ancestry is well formed for the format and primary key type.

Types

t()

@type t() :: :materialized_path | :materialized_path2

Functions

child_ancestry(arg1, ancestry, id)

@spec child_ancestry(t(), String.t() | nil, term()) :: String.t()

Ancestry value of the children of a node with the given ancestry and id.

depth(format, ancestry)

@spec depth(t(), String.t() | nil) :: non_neg_integer()

Depth of a node with the given ancestry value (roots have depth 0).

generate(format, ids)

@spec generate(t(), [term()]) :: String.t() | nil

Builds an ancestry value from a list of ancestor ids, root first.

parse(arg1, ancestry)

@spec parse(t(), String.t() | nil) :: [String.t()]

Splits an ancestry value into its id segments (as strings), root first.

root_value(atom)

@spec root_value(t()) :: String.t() | nil

Value stored in the ancestry column of a root node.

valid?(format, ancestry, type)

@spec valid?(t(), String.t() | nil, Ecto.Type.t()) :: boolean()

Returns true if ancestry is well formed for the format and primary key type.