Skip to main content

fraiseql_core/schema/
hierarchy.rs

1//! Typed hierarchy definitions for ID-based ltree operators.
2//!
3//! Replaces raw `serde_json::Value` in `CompiledSchema.hierarchies_config` with
4//! a strongly-typed [`HierarchiesConfig`] map, giving compile-time field access
5//! and eliminating manual JSON traversal at runtime.
6
7use std::collections::HashMap;
8
9use serde::{Deserialize, Serialize};
10
11/// A single hierarchy definition mapping a name to its database table and ltree
12/// path column.
13///
14/// Compiled from the `[hierarchies.<name>]` TOML section. The `id` column is
15/// always `id` (UUID) per the trinity pattern and is not configurable.
16#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
17pub struct HierarchyDefinition {
18    /// Database table containing the ltree column (e.g., `"tb_category"`).
19    pub table: String,
20
21    /// Name of the ltree column in the table (e.g., `"category_path"`).
22    pub path_column: String,
23}
24
25/// Maps hierarchy names to their [`HierarchyDefinition`].
26pub type HierarchiesConfig = HashMap<String, HierarchyDefinition>;