Skip to main content

icydb_core/db/
catalog.rs

1//! Module: db::catalog
2//! Responsibility: catalog-level metadata DTOs for SHOW-style introspection.
3//! Does not own: schema validation, query planning, or runtime store policy.
4//! Boundary: projects accepted entity and registered-store metadata for callers.
5
6use serde::Deserialize;
7
8///
9/// EntityCatalogCounts
10///
11/// Compact count metadata for one `SHOW ENTITIES` row.
12///
13
14#[cfg_attr(
15    doc,
16    doc = "EntityCatalogCounts\n\nCompact count metadata for one SHOW ENTITIES row."
17)]
18#[derive(Clone, Debug, Deserialize, Eq, PartialEq)]
19pub struct EntityCatalogCounts {
20    columns: u32,
21    indexes: u32,
22    relations: u32,
23    schema_version: u32,
24}
25
26impl EntityCatalogCounts {
27    /// Construct compact entity catalog count metadata.
28    #[must_use]
29    pub const fn new(columns: u32, indexes: u32, relations: u32, schema_version: u32) -> Self {
30        Self {
31            columns,
32            indexes,
33            relations,
34            schema_version,
35        }
36    }
37}
38
39#[cfg_attr(
40    doc,
41    doc = "EntityCatalogDescription\n\nRuntime catalog entry for one accepted entity."
42)]
43#[derive(Clone, Debug, Deserialize, Eq, PartialEq, serde::Serialize)]
44pub struct EntityCatalogDescription {
45    entity_name: String,
46    entity_path: String,
47    store_path: String,
48    storage: String,
49    columns: u32,
50    indexes: u32,
51    relations: u32,
52    schema_version: u32,
53}
54
55impl EntityCatalogDescription {
56    /// Construct one entity catalog entry.
57    #[must_use]
58    pub const fn new(
59        entity_name: String,
60        entity_path: String,
61        store_path: String,
62        storage: String,
63        counts: EntityCatalogCounts,
64    ) -> Self {
65        Self {
66            entity_name,
67            entity_path,
68            store_path,
69            storage,
70            columns: counts.columns,
71            indexes: counts.indexes,
72            relations: counts.relations,
73            schema_version: counts.schema_version,
74        }
75    }
76
77    /// Stable external entity name.
78    #[must_use]
79    pub const fn entity_name(&self) -> &str {
80        self.entity_name.as_str()
81    }
82
83    /// Runtime entity path.
84    #[must_use]
85    pub const fn entity_path(&self) -> &str {
86        self.entity_path.as_str()
87    }
88
89    /// Owning store path.
90    #[must_use]
91    pub const fn store_path(&self) -> &str {
92        self.store_path.as_str()
93    }
94
95    /// User-facing storage mode for the owning store.
96    #[must_use]
97    pub const fn storage(&self) -> &str {
98        self.storage.as_str()
99    }
100
101    /// Number of top-level columns registered for this entity.
102    #[must_use]
103    pub const fn columns(&self) -> u32 {
104        self.columns
105    }
106
107    /// Number of accepted secondary indexes registered for this entity.
108    #[must_use]
109    pub const fn indexes(&self) -> u32 {
110        self.indexes
111    }
112
113    /// Number of relation fields registered for this entity.
114    #[must_use]
115    pub const fn relations(&self) -> u32 {
116        self.relations
117    }
118
119    /// Accepted schema version for this entity.
120    #[must_use]
121    pub const fn schema_version(&self) -> u32 {
122        self.schema_version
123    }
124}
125
126///
127/// StoreCatalogDescription
128///
129/// One runtime-registered store entry for `SHOW STORES`.
130///
131
132#[cfg_attr(
133    doc,
134    doc = "StoreCatalogDescription\n\nRuntime catalog entry for one registered store."
135)]
136#[derive(Clone, Debug, Deserialize, Eq, PartialEq, serde::Serialize)]
137pub struct StoreCatalogDescription {
138    store_path: String,
139    storage: String,
140}
141
142impl StoreCatalogDescription {
143    /// Construct one store catalog entry.
144    #[must_use]
145    pub const fn new(store_path: String, storage: String) -> Self {
146        Self {
147            store_path,
148            storage,
149        }
150    }
151
152    /// Store path.
153    #[must_use]
154    pub const fn store_path(&self) -> &str {
155        self.store_path.as_str()
156    }
157
158    /// User-facing storage mode.
159    #[must_use]
160    pub const fn storage(&self) -> &str {
161        self.storage.as_str()
162    }
163}
164
165///
166/// MemoryCatalogDescription
167///
168/// One runtime-registered stable-memory allocation entry for `SHOW MEMORY`.
169///
170
171#[cfg_attr(
172    doc,
173    doc = "MemoryCatalogDescription\n\nRuntime catalog entry for one stable-memory allocation."
174)]
175#[derive(Clone, Debug, Deserialize, Eq, PartialEq, serde::Serialize)]
176pub struct MemoryCatalogDescription {
177    tag: String,
178    memory_id: u8,
179    store_path: String,
180}
181
182impl MemoryCatalogDescription {
183    /// Construct one memory catalog entry.
184    #[must_use]
185    pub const fn new(tag: String, memory_id: u8, store_path: String) -> Self {
186        Self {
187            tag,
188            memory_id,
189            store_path,
190        }
191    }
192
193    /// Durable stable-memory key used as the memory tag.
194    #[must_use]
195    pub const fn tag(&self) -> &str {
196        self.tag.as_str()
197    }
198
199    /// Stable-memory manager ID.
200    #[must_use]
201    pub const fn memory_id(&self) -> u8 {
202        self.memory_id
203    }
204
205    /// Owning store path.
206    #[must_use]
207    pub const fn store_path(&self) -> &str {
208        self.store_path.as_str()
209    }
210}