reifydb_core/interface/catalog/
namespace.rs1use crate::interface::catalog::id::NamespaceId;
5
6impl NamespaceId {
7 pub const ROOT: NamespaceId = NamespaceId(0);
8 pub const SYSTEM: NamespaceId = NamespaceId(1);
9 pub const DEFAULT: NamespaceId = NamespaceId(2);
10 pub const SYSTEM_CONFIG: NamespaceId = NamespaceId(3);
11 pub const SYSTEM_METRICS: NamespaceId = NamespaceId(4);
12 pub const SYSTEM_METRICS_STORAGE: NamespaceId = NamespaceId(5);
13 pub const SYSTEM_METRICS_CDC: NamespaceId = NamespaceId(6);
14 pub const SYSTEM_PROCEDURES: NamespaceId = NamespaceId(7);
15 pub const SYSTEM_BINDINGS: NamespaceId = NamespaceId(8);
16 pub const RQL: NamespaceId = NamespaceId(9);
17 pub const SYSTEM_METRICS_PROFILER: NamespaceId = NamespaceId(10);
18 pub const SYSTEM_METRICS_PROFILER_QUERY: NamespaceId = NamespaceId(11);
19 pub const SYSTEM_METRICS_PROFILER_TXN: NamespaceId = NamespaceId(12);
20 pub const SYSTEM_METRICS_PROFILER_STORAGE: NamespaceId = NamespaceId(13);
21 pub const SYSTEM_METRICS_PROFILER_PLAN: NamespaceId = NamespaceId(14);
22 pub const SYSTEM_METRICS_PROFILER_CDC: NamespaceId = NamespaceId(15);
23 pub const SYSTEM_METRICS_PROFILER_FLOW: NamespaceId = NamespaceId(16);
24 pub const SYSTEM_METRICS_RUNTIME: NamespaceId = NamespaceId(17);
25 pub const SYSTEM_METRICS_RUNTIME_MEMORY: NamespaceId = NamespaceId(18);
26 pub const SYSTEM_METRICS_RUNTIME_WATERMARKS: NamespaceId = NamespaceId(19);
27}
28
29#[derive(Debug, Clone, PartialEq)]
30pub enum Namespace {
31 Local {
32 id: NamespaceId,
33 name: String,
34 local_name: String,
35 parent_id: NamespaceId,
36 },
37 Remote {
38 id: NamespaceId,
39 name: String,
40 local_name: String,
41 parent_id: NamespaceId,
42 address: String,
43 token: Option<String>,
44 },
45}
46
47impl Namespace {
48 pub fn id(&self) -> NamespaceId {
49 match self {
50 Namespace::Local {
51 id,
52 ..
53 }
54 | Namespace::Remote {
55 id,
56 ..
57 } => *id,
58 }
59 }
60
61 pub fn name(&self) -> &str {
62 match self {
63 Namespace::Local {
64 name,
65 ..
66 }
67 | Namespace::Remote {
68 name,
69 ..
70 } => name,
71 }
72 }
73
74 pub fn local_name(&self) -> &str {
75 match self {
76 Namespace::Local {
77 local_name,
78 ..
79 }
80 | Namespace::Remote {
81 local_name,
82 ..
83 } => local_name,
84 }
85 }
86
87 pub fn parent_id(&self) -> NamespaceId {
88 match self {
89 Namespace::Local {
90 parent_id,
91 ..
92 }
93 | Namespace::Remote {
94 parent_id,
95 ..
96 } => *parent_id,
97 }
98 }
99
100 pub fn address(&self) -> Option<&str> {
101 match self {
102 Namespace::Remote {
103 address,
104 ..
105 } => Some(address),
106 _ => None,
107 }
108 }
109
110 pub fn token(&self) -> Option<&str> {
111 match self {
112 Namespace::Remote {
113 token,
114 ..
115 } => token.as_deref(),
116 _ => None,
117 }
118 }
119
120 pub fn is_remote(&self) -> bool {
121 matches!(self, Namespace::Remote { .. })
122 }
123
124 pub fn system() -> Self {
125 Self::Local {
126 id: NamespaceId::SYSTEM,
127 name: "system".to_string(),
128 local_name: "system".to_string(),
129 parent_id: NamespaceId::ROOT,
130 }
131 }
132
133 pub fn default_namespace() -> Self {
134 Self::Local {
135 id: NamespaceId::DEFAULT,
136 name: "default".to_string(),
137 local_name: "default".to_string(),
138 parent_id: NamespaceId::ROOT,
139 }
140 }
141}