reifydb_catalog/store/dictionary/
get.rs1use reifydb_core::{
5 interface::{DictionaryDef, DictionaryId, QueryTransaction},
6 return_internal_error,
7};
8
9use crate::CatalogStore;
10
11impl CatalogStore {
12 pub async fn get_dictionary(
13 rx: &mut impl QueryTransaction,
14 dictionary: DictionaryId,
15 ) -> crate::Result<DictionaryDef> {
16 match Self::find_dictionary(rx, dictionary).await? {
17 Some(dict) => Ok(dict),
18 None => return_internal_error!(
19 "Dictionary with ID {:?} not found in catalog. This indicates a critical catalog inconsistency.",
20 dictionary
21 ),
22 }
23 }
24}
25
26#[cfg(test)]
27mod tests {
28 use reifydb_core::interface::DictionaryId;
29 use reifydb_engine::test_utils::create_test_command_transaction;
30 use reifydb_type::Type;
31
32 use crate::{CatalogStore, store::dictionary::create::DictionaryToCreate, test_utils::ensure_test_namespace};
33
34 #[tokio::test]
35 async fn test_get_dictionary_exists() {
36 let mut txn = create_test_command_transaction().await;
37 let test_namespace = ensure_test_namespace(&mut txn).await;
38
39 let to_create = DictionaryToCreate {
40 namespace: test_namespace.id,
41 dictionary: "test_dict".to_string(),
42 value_type: Type::Utf8,
43 id_type: Type::Uint2,
44 fragment: None,
45 };
46
47 let created = CatalogStore::create_dictionary(&mut txn, to_create).await.unwrap();
48
49 let result = CatalogStore::get_dictionary(&mut txn, created.id).await.unwrap();
50
51 assert_eq!(result.id, created.id);
52 assert_eq!(result.name, "test_dict");
53 assert_eq!(result.value_type, Type::Utf8);
54 assert_eq!(result.id_type, Type::Uint2);
55 }
56
57 #[tokio::test]
58 async fn test_get_dictionary_not_exists() {
59 let mut txn = create_test_command_transaction().await;
60
61 let result = CatalogStore::get_dictionary(&mut txn, DictionaryId(999));
62
63 assert!(result.await.is_err());
64 }
65}