Skip to main content

reifydb_catalog/
lib.rs

1// SPDX-License-Identifier: AGPL-3.0-or-later
2// Copyright (c) 2025 ReifyDB
3
4// #![cfg_attr(not(debug_assertions), deny(warnings))]
5
6use reifydb_core::interface::{
7	catalog::{
8		id::{NamespaceId, SubscriptionId},
9		subscription::SubscriptionDef,
10	},
11	version::{ComponentType, HasVersion, SystemVersion},
12};
13use reifydb_transaction::transaction::{Transaction, admin::AdminTransaction};
14
15pub mod catalog;
16pub mod materialized;
17pub mod schema;
18pub(crate) mod store;
19pub mod system;
20pub mod test_utils;
21pub mod vtable;
22/// Result type alias for this crate
23pub type Result<T> = reifydb_type::Result<T>;
24
25pub(crate) struct CatalogStore;
26
27/// Find a subscription by ID directly from storage.
28///
29/// This is a low-level function that bypasses the MaterializedCatalog cache.
30/// For most use cases, prefer using `Catalog::find_subscription` instead.
31pub fn find_subscription(txn: &mut Transaction<'_>, id: SubscriptionId) -> Result<Option<SubscriptionDef>> {
32	CatalogStore::find_subscription(txn, id)
33}
34
35/// Delete a subscription and all its associated data (columns, rows, metadata).
36///
37/// This is a low-level function that performs complete cleanup of a subscription.
38/// Use this when cleaning up subscriptions after a WebSocket connection closes.
39pub fn delete_subscription(txn: &mut AdminTransaction, id: SubscriptionId) -> Result<()> {
40	CatalogStore::delete_subscription(txn, id)
41}
42
43/// Delete a flow by its name within a namespace.
44///
45/// This is useful for cleaning up flows associated with subscriptions,
46/// where the flow name is derived from the subscription ID.
47pub fn delete_flow_by_name(txn: &mut AdminTransaction, namespace: NamespaceId, name: &str) -> Result<()> {
48	CatalogStore::delete_flow_by_name(txn, namespace, name)
49}
50
51pub struct CatalogVersion;
52
53impl HasVersion for CatalogVersion {
54	fn version(&self) -> SystemVersion {
55		SystemVersion {
56			name: env!("CARGO_PKG_NAME")
57				.strip_prefix("reifydb-")
58				.unwrap_or(env!("CARGO_PKG_NAME"))
59				.to_string(),
60			version: env!("CARGO_PKG_VERSION").to_string(),
61			description: "Database catalog and metadata management module".to_string(),
62			r#type: ComponentType::Module,
63		}
64	}
65}