Skip to main content

uqa_engine/capabilities/
view_removal.rs

1//
2// Unified Query Algebra
3//
4// Copyright (c) 2023-2026 Cognica, Inc.
5//
6
7//! Connect view removal to existing transaction, registry and event boundaries.
8use crate::Engine;
9use uqa_core::RelationIdentity;
10use uqa_execution::schema::view_removal::context::{
11    ViewRemovalContext, ViewRemovalEvents, ViewRemovalPublication,
12};
13use uqa_sql::SQLError;
14use uqa_storage::StorageBackendResult;
15
16impl Engine {
17    pub(crate) fn view_removal_context(&self) -> ViewRemovalContext<'_> {
18        ViewRemovalContext {
19            registry: self,
20            publication: self,
21            changes: self,
22            events: self,
23            ownership: self.view_ownership_context(),
24        }
25    }
26    pub fn drop_view(&self, name: &str) -> Result<bool, SQLError> {
27        self.with_implicit_definition_transaction(|engine| {
28            uqa_execution::schema::removal::direct::drop_view(
29                &engine.relation_removal_context(),
30                name,
31            )
32        })
33    }
34}
35impl ViewRemovalEvents for Engine {
36    fn drop_relation_events_inner(&self, relation: &RelationIdentity) -> StorageBackendResult<()> {
37        self.event_lifecycle_context()
38            .drop_relation_events_inner(relation)
39    }
40}
41impl ViewRemovalPublication for Engine {
42    fn drop_view(
43        &self,
44        relation: &RelationIdentity,
45        object: Option<[u8; 16]>,
46    ) -> StorageBackendResult<Option<bool>> {
47        self.storage
48            .catalog
49            .as_ref()
50            .map(|catalog| {
51                let removed = catalog.drop_view(relation)?;
52                if let Some(object) = object {
53                    uqa_execution::catalog::definition_revision::remove_view(
54                        catalog.as_ref(),
55                        object,
56                    )?;
57                }
58                Ok(removed)
59            })
60            .transpose()
61    }
62}