reifydb_catalog/transaction/
flow.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	interface::{FlowDef, FlowId, NamespaceId, QueryTransaction},
6	return_error,
7};
8use reifydb_type::{IntoFragment, diagnostic::catalog::flow_not_found};
9
10use crate::{CatalogStore, transaction::MaterializedCatalogTransaction};
11
12pub trait CatalogFlowQueryOperations {
13	fn find_flow(&mut self, id: FlowId) -> crate::Result<Option<FlowDef>>;
14
15	fn find_flow_by_name<'a>(
16		&mut self,
17		namespace: NamespaceId,
18		name: impl IntoFragment<'a>,
19	) -> crate::Result<Option<FlowDef>>;
20
21	fn get_flow(&mut self, id: FlowId) -> crate::Result<FlowDef>;
22
23	fn get_flow_by_name<'a>(
24		&mut self,
25		namespace: NamespaceId,
26		name: impl IntoFragment<'a>,
27	) -> crate::Result<FlowDef>;
28}
29
30impl<QT: QueryTransaction + MaterializedCatalogTransaction> CatalogFlowQueryOperations for QT {
31	fn find_flow(&mut self, id: FlowId) -> crate::Result<Option<FlowDef>> {
32		CatalogStore::find_flow(self, id)
33	}
34
35	fn find_flow_by_name<'a>(
36		&mut self,
37		namespace: NamespaceId,
38		name: impl IntoFragment<'a>,
39	) -> crate::Result<Option<FlowDef>> {
40		let name = name.into_fragment();
41		CatalogStore::find_flow_by_name(self, namespace, name.text())
42	}
43
44	fn get_flow(&mut self, id: FlowId) -> crate::Result<FlowDef> {
45		CatalogStore::get_flow(self, id)
46	}
47
48	fn get_flow_by_name<'a>(
49		&mut self,
50		namespace: NamespaceId,
51		name: impl IntoFragment<'a>,
52	) -> crate::Result<FlowDef> {
53		let name = name.into_fragment();
54		let name_text = name.text().to_string();
55		let flow = self.find_flow_by_name(namespace, name.clone())?;
56		match flow {
57			Some(f) => Ok(f),
58			None => {
59				let namespace = CatalogStore::get_namespace(self, namespace)?;
60				return_error!(flow_not_found(name, &namespace.name, &name_text))
61			}
62		}
63	}
64}