Ecto adjacency list and tree traversal library for Elixir using CTEs and a parent_id field.
Arbor is an Elixir library designed for adjacency list and tree traversal using Ecto. It solves the problem of efficiently querying hierarchical data in SQL databases by utilizing Common Table Expressions (CTEs) and a `parent_id` field, allowing developers to easily manage tree-like structures such as comments, categories, or organizational charts.
Elixir developers working with Ecto and needing to handle hierarchical data models, such as those building applications with nested comments, product categories, or any tree-based data structures.
Developers choose Arbor for its simplicity and performance, as it provides composable Ecto queries for tree traversal without requiring complex SQL or additional dependencies, and it has been benchmarked to handle large datasets efficiently.
Ecto elixir adjacency list and tree traversal. Supports Ecto versions 2 and 3.
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Leverages SQL CTEs for fast traversal, with benchmarks showing efficient performance on tables with over 10 million rows, as detailed in the README's timing results.
All methods return standard Ecto queries, allowing easy chaining with filters, orders, and other query conditions, as shown in usage examples like `Comment.siblings |> Comment.order_by_popularity`.
Requires only a `parent_id` field and minimal setup in Ecto schemas, with options to customize keys and CTE names to fit existing database designs.
Supports optional depth parameters for descendants queries, enabling performance optimizations by limiting tree depth, as demonstrated in the `descendants(2)` example.
The `orphan_strategy` option defaults to `:nothing` and is admitted as unimplemented in the README, leaving gaps in managing orphaned records during deletions or updates.
Relies on databases with CTE support, primarily PostgreSQL, making it unsuitable for projects using NoSQL or older SQL systems without CTE capabilities.
Focuses on querying rather than full CRUD operations; lacks built-in functions for complex tree manipulations like bulk inserts or subtree reorganizations.
Requires separate dependency versions for Ecto 2 and Ecto 3, which can lead to maintenance overhead and compatibility issues in mixed environments.