| Crates.io | closure-tree-macros |
| lib.rs | closure-tree-macros |
| version | 0.0.1 |
| created_at | 2025-10-20 10:45:10.995092+00 |
| updated_at | 2025-10-20 10:45:10.995092+00 |
| description | Procedural macros for closure-tree. |
| homepage | https://github.com/ClosureTree/closure-tree-rs |
| repository | https://github.com/ClosureTree/closure-tree-rs |
| max_upload_size | |
| id | 1891734 |
| size | 17,659 |
A SeaORM-friendly port of Ruby's closure_tree.
Early preview (0.0.1). PostgreSQL only. Contributions welcome.
[dependencies]
closure-tree = "0.0.1"
use closure_tree::ClosureTreeRepository;
use closure_tree::ClosureTreeModelDerive as ClosureTreeModel;
use sea_orm::entity::prelude::*;
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, ClosureTreeModel)]
#[sea_orm(table_name = "nodes")]
#[closure_tree(hierarchy_module = "crate::entity::node_hierarchy", hierarchy_table = "node_hierarchies")]
pub struct Model {
#[sea_orm(primary_key)]
pub id: i32,
pub parent_id: Option<i32>,
pub name: String,
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let db = sea_orm::Database::connect("postgres://...").await?;
let repo = ClosureTreeRepository::<entity::node::Model>::new();
let _leaf = repo
.find_or_create_by_path(&db, &["root", "child", "leaf"])
.await?;
Ok(())
}
#[derive(ClosureTreeModel)]).parent, descendants, find_by_path, find_or_create_by_path, etc.).pg_advisory_lock, rebuild utilities.hash_tree, dependent strategies, and some Ruby APIs are not yet ported.cargo fmt
cargo clippy --all-targets -- -D warnings
cargo test
Requires Docker Postgres at postgres://closure_tree:closure_tree_pass@localhost:5434/closure_tree_test (see tests/postgres.rs).