reifydb_catalog/store/namespace/
list.rs

1// Copyright (c) reifydb.com 2025
2// This file is licensed under the AGPL-3.0-or-later, see license.md file
3
4use reifydb_core::interface::{Key, NamespaceDef, NamespaceKey, QueryTransaction};
5
6use crate::{CatalogStore, store::namespace::layout::namespace};
7
8impl CatalogStore {
9	pub async fn list_namespaces_all(rx: &mut impl QueryTransaction) -> crate::Result<Vec<NamespaceDef>> {
10		let mut result = Vec::new();
11
12		let namespace_range = NamespaceKey::full_scan();
13
14		let batch = rx.range(namespace_range).await?;
15
16		for entry in batch.items {
17			if let Some(key) = Key::decode(&entry.key) {
18				if let Key::Namespace(namespace_key) = key {
19					let namespace_id = namespace_key.namespace;
20
21					let name =
22						namespace::LAYOUT.get_utf8(&entry.values, namespace::NAME).to_string();
23					let namespace_def = NamespaceDef {
24						id: namespace_id,
25						name,
26					};
27
28					result.push(namespace_def);
29				}
30			}
31		}
32
33		result.push(NamespaceDef::system());
34
35		Ok(result)
36	}
37}