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