1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
//! Nested set trees for [Laravel Rust](https://crates.io/crates/laravel-rust) models.
//!
//! A nested set stores a tree in one table: each row keeps the `lft` and `rgt` bounds of its
//! subtree, so a whole subtree or every ancestor of a node is one indexed query.
//!
//! ```no_run
//! use laravel::model::{Column, model};
//! use laravel_nestedset::NestedSet;
//!
//! #[model]
//! pub struct Category {
//! pub id: i64,
//! pub name: String,
//! #[default]
//! pub lft: i64,
//! #[default]
//! pub rgt: i64,
//! pub parent_id: Option<i64>,
//! }
//!
//! impl NestedSet for Category {
//! fn lft_column() -> Column<Self, i64> {
//! Category::lft
//! }
//!
//! fn rgt_column() -> Column<Self, i64> {
//! Category::rgt
//! }
//!
//! fn parent_column() -> Column<Self, Option<i64>> {
//! Category::parent_id
//! }
//! }
//!
//! # async fn example() -> laravel::Result<()> {
//! let mut shop = Category::create_root(Category::create().name("Shop")).await?;
//! let mut phones = shop.create_child(Category::create().name("Phones")).await?;
//! let android = phones.create_child(Category::create().name("Android")).await?;
//!
//! let subtree = shop.descendants().get().await?; // Phones, Android
//! let breadcrumbs = android.ancestors().get().await?; // Shop, Phones
//! # Ok(())
//! # }
//! ```
//!
//! The migration adds the columns with
//! [`table.nested_set()`](NestedSetBlueprint::nested_set). From there, [`NestedSet`] has:
//!
//! - creating: [`create_root`](NestedSet::create_root), [`create_child`](NestedSet::create_child),
//! [`create_after`](NestedSet::create_after), [`create_tree`](NestedSet::create_tree) from
//! nested [`NewNode`]s, and more;
//! - moving a subtree: [`append_to`](NestedSet::append_to),
//! [`insert_before`](NestedSet::insert_before), [`make_root`](NestedSet::make_root),
//! [`up`](NestedSet::up), and more;
//! - deleting a subtree: [`delete_subtree`](NestedSet::delete_subtree);
//! - queries: [`descendants`](NestedSet::descendants), [`ancestors`](NestedSet::ancestors),
//! [`siblings`](NestedSet::siblings), [`children`](NestedSet::children), and more;
//! - conditions for any query: [`where_descendant_of`](NestedSet::where_descendant_of),
//! [`where_ancestor_of`](NestedSet::where_ancestor_of), and more;
//! - loading by key: [`ancestors_of`](NestedSet::ancestors_of),
//! [`subtree_of`](NestedSet::subtree_of), and more;
//! - drag-and-drop saves: [`arrange`](NestedSet::arrange) from nested [`Arrangement`]s;
//! - repairs: [`check_tree`](NestedSet::check_tree) and [`fix_tree`](NestedSet::fix_tree), also
//! from the console through [`NestedSetServiceProvider`].
//!
//! [`LoadRelatives`] loads the ancestors or subtrees of a whole list with one query.
//!
//! [`IntoTree::into_tree`] nests a query's result into [`TreeNode`]s for JSON and templates, and
//! [`Scope`] keeps several trees in one table. Every write locks its tree, so concurrent writers
//! take turns. See the [README](https://github.com/axvilab/laravel-nestedset-rs) for the guide.
pub use crateArrangement;
pub use crateTreeReport;
pub use crateNestedSetServiceProvider;
pub use crateNestedSetError;
pub use crate;
pub use crateNestedSet;
pub use crate;
pub use crateNestedSetBlueprint;
pub use crateScope;
pub use crate;