reifydb_catalog/transaction/
source.rs1use reifydb_core::{
5 error,
6 interface::{NamespaceId, QueryTransaction, SourceDef, SourceId},
7};
8use reifydb_type::{IntoFragment, internal};
9
10use crate::{CatalogTableQueryOperations, CatalogViewQueryOperations};
11
12pub trait CatalogSourceQueryOperations {
13 fn find_source_by_name<'a>(
14 &mut self,
15 namespace: NamespaceId,
16 source: impl IntoFragment<'a>,
17 ) -> crate::Result<Option<SourceDef>>;
18
19 fn find_source(&mut self, id: SourceId) -> crate::Result<Option<SourceDef>>;
20
21 fn get_source(&mut self, id: SourceId) -> crate::Result<SourceDef>;
22
23 fn get_source_by_name<'a>(
24 &mut self,
25 namespace: NamespaceId,
26 name: impl IntoFragment<'a>,
27 ) -> crate::Result<SourceDef>;
28}
29
30impl<T: QueryTransaction + CatalogTableQueryOperations + CatalogViewQueryOperations> CatalogSourceQueryOperations
31 for T
32{
33 fn find_source_by_name<'a>(
34 &mut self,
35 _namespace: NamespaceId,
36 _source: impl IntoFragment<'a>,
37 ) -> reifydb_core::Result<Option<SourceDef>> {
38 todo!()
39 }
40
41 fn find_source(&mut self, id: SourceId) -> reifydb_core::Result<Option<SourceDef>> {
42 match id {
43 SourceId::Table(table_id) => {
44 Ok(self.find_table(table_id)?.and_then(|s| Some(SourceDef::Table(s))))
45 }
46 SourceId::View(view_id) => Ok(self.find_view(view_id)?.and_then(|s| Some(SourceDef::View(s)))),
47 SourceId::Flow(_) => unimplemented!(),
48 SourceId::TableVirtual(_) => unimplemented!(),
49 SourceId::RingBuffer(_) => unimplemented!(),
50 SourceId::Dictionary(_) => unimplemented!(),
51 }
52 }
53
54 fn get_source(&mut self, id: SourceId) -> reifydb_core::Result<SourceDef> {
55 self.find_source(id)?.ok_or_else(|| {
56 error!(internal!(
57 "Source with ID {:?} not found in catalog. This indicates a critical catalog inconsistency.",
58 id
59 ))
60 })
61 }
62
63 fn get_source_by_name<'a>(
64 &mut self,
65 _namespace: NamespaceId,
66 _name: impl IntoFragment<'a>,
67 ) -> reifydb_core::Result<SourceDef> {
68 todo!()
69 }
70}