Skip to main content

uqa_sql/catalog/roles/dependencies/
context.rs

1//
2// Unified Query Algebra
3//
4// Copyright (c) 2023-2026 Cognica, Inc.
5//
6
7//! Retained catalog inputs for ordered role dependency checks.
8
9use crate::{
10    catalog::{
11        security::{database::DatabaseSecurity, SchemaSecurity, SequenceSecurity, TableSecurity},
12        stored_view::StoredView,
13    },
14    routines::SQLUserFunction,
15};
16use std::{collections::BTreeMap, ops::Deref, sync::Arc};
17use uqa_core::RelationIdentity;
18
19pub type RoleDependencyRead<'a, T> = Box<dyn Deref<Target = T> + 'a>;
20/// Table security is read lazily at each visited role and relation pair.
21pub trait RoleTableSecurity {
22    fn security(&self) -> TableSecurity;
23}
24/// The iterator borrows its entries while the original table registry guard is retained.
25pub trait RoleTablesRead {
26    fn iter(&self) -> Box<dyn Iterator<Item = (&RelationIdentity, &dyn RoleTableSecurity)> + '_>;
27}
28pub trait RoleDependencyCatalog {
29    fn database(&self) -> RoleDependencyRead<'_, DatabaseSecurity>;
30    fn schemas(&self) -> RoleDependencyRead<'_, BTreeMap<String, SchemaSecurity>>;
31    fn tables(&self) -> Box<dyn RoleTablesRead + '_>;
32    fn views(&self) -> RoleDependencyRead<'_, BTreeMap<RelationIdentity, StoredView>>;
33    fn foreign_tables(&self) -> RoleDependencyRead<'_, BTreeMap<RelationIdentity, TableSecurity>>;
34    fn sequences(&self) -> RoleDependencyRead<'_, BTreeMap<RelationIdentity, SequenceSecurity>>;
35    fn routines(&self) -> RoleDependencyRead<'_, BTreeMap<String, Vec<Arc<SQLUserFunction>>>>;
36}