reddb_server/application/
tree.rs1use crate::application::ports::RuntimeTreePort;
2use crate::runtime::RuntimeQueryResult;
3use crate::storage::schema::Value;
4use crate::storage::unified::MetadataValue;
5use crate::RedDBResult;
6
7#[derive(Debug, Clone)]
8pub struct TreeNodeInput {
9 pub label: String,
10 pub node_type: Option<String>,
11 pub properties: Vec<(String, Value)>,
12 pub metadata: Vec<(String, MetadataValue)>,
13 pub max_children: Option<usize>,
14}
15
16#[derive(Debug, Clone)]
17pub struct CreateTreeInput {
18 pub collection: String,
19 pub name: String,
20 pub root: TreeNodeInput,
21 pub default_max_children: usize,
22 pub if_not_exists: bool,
23}
24
25#[derive(Debug, Clone)]
26pub struct DropTreeInput {
27 pub collection: String,
28 pub name: String,
29 pub if_exists: bool,
30}
31
32#[derive(Debug, Clone, Copy, PartialEq, Eq)]
33pub enum TreePositionInput {
34 First,
35 Last,
36 Index(usize),
37}
38
39#[derive(Debug, Clone)]
40pub struct InsertTreeNodeInput {
41 pub collection: String,
42 pub tree_name: String,
43 pub parent_id: u64,
44 pub node: TreeNodeInput,
45 pub position: TreePositionInput,
46}
47
48#[derive(Debug, Clone)]
49pub struct MoveTreeNodeInput {
50 pub collection: String,
51 pub tree_name: String,
52 pub node_id: u64,
53 pub parent_id: u64,
54 pub position: TreePositionInput,
55}
56
57#[derive(Debug, Clone)]
58pub struct DeleteTreeNodeInput {
59 pub collection: String,
60 pub tree_name: String,
61 pub node_id: u64,
62}
63
64#[derive(Debug, Clone)]
65pub struct ValidateTreeInput {
66 pub collection: String,
67 pub tree_name: String,
68}
69
70#[derive(Debug, Clone)]
71pub struct RebalanceTreeInput {
72 pub collection: String,
73 pub tree_name: String,
74 pub dry_run: bool,
75}
76
77pub struct TreeUseCases<'a, P: ?Sized> {
78 runtime: &'a P,
79}
80
81impl<'a, P: RuntimeTreePort + ?Sized> TreeUseCases<'a, P> {
82 pub fn new(runtime: &'a P) -> Self {
83 Self { runtime }
84 }
85
86 pub fn create_tree(&self, input: CreateTreeInput) -> RedDBResult<RuntimeQueryResult> {
87 self.runtime.create_tree(input)
88 }
89
90 pub fn drop_tree(&self, input: DropTreeInput) -> RedDBResult<RuntimeQueryResult> {
91 self.runtime.drop_tree(input)
92 }
93
94 pub fn insert_node(&self, input: InsertTreeNodeInput) -> RedDBResult<RuntimeQueryResult> {
95 self.runtime.insert_tree_node(input)
96 }
97
98 pub fn move_node(&self, input: MoveTreeNodeInput) -> RedDBResult<RuntimeQueryResult> {
99 self.runtime.move_tree_node(input)
100 }
101
102 pub fn delete_node(&self, input: DeleteTreeNodeInput) -> RedDBResult<RuntimeQueryResult> {
103 self.runtime.delete_tree_node(input)
104 }
105
106 pub fn validate(&self, input: ValidateTreeInput) -> RedDBResult<RuntimeQueryResult> {
107 self.runtime.validate_tree(input)
108 }
109
110 pub fn rebalance(&self, input: RebalanceTreeInput) -> RedDBResult<RuntimeQueryResult> {
111 self.runtime.rebalance_tree(input)
112 }
113}