uqa_execution/catalog/
services.rs1use super::RelationNameResolution;
9use uqa_core::Value;
10use uqa_sql::catalog::roles::RoleReference;
11use uqa_sql::catalog::session::{CursorMetadata, PreparedStatementMetadata};
12use uqa_sql::{
13 ast::{Expr, TriggerEvent},
14 SQLError,
15};
16
17pub trait CatalogSession: Sync {
18 fn current_role(&self) -> RoleReference;
19 fn temporary_schema_name(&self) -> String;
20 fn relation_name_resolution(&self) -> RelationNameResolution;
21 fn show_parameter(&self, name: &str) -> Result<(String, String), SQLError>;
23 fn parameter_settings(&self) -> Vec<uqa_sql::semantics::parameters::setting::ParameterSetting>;
25 fn prepared_statements(&self) -> Vec<PreparedStatementMetadata>;
26 fn cursors(&self) -> Vec<CursorMetadata>;
27}
28pub trait CatalogExpressionEvaluation: Sync {
29 fn evaluate(&self, expression: &Expr) -> Result<Value, SQLError>;
30}
31pub trait RelationCounts: Sync {
32 fn table_doc_count(&self, table: &str) -> Result<u64, SQLError>;
33}
34pub use uqa_sql::catalog::view::ViewMutationCapabilities;
35pub struct ViewCatalogMetadata {
36 pub catalog: ViewMutationCapabilities,
37 pub catalog_columns: Vec<bool>,
38 pub check_option: String,
39}
40pub trait ViewCatalogCapabilities: Sync {
41 fn view_updatability(&self, name: &str) -> Result<ViewCatalogMetadata, SQLError>;
42 fn has_instead_of_trigger(&self, name: &str, event: TriggerEvent) -> Result<bool, SQLError>;
43 fn view_updatability_with_catalog(
44 &self,
45 name: &str,
46 _catalog: &super::CatalogReadView,
47 _resolution: &RelationNameResolution,
48 ) -> Result<ViewCatalogMetadata, SQLError> {
49 self.view_updatability(name)
50 }
51 fn has_instead_of_trigger_with_catalog(
52 &self,
53 name: &str,
54 event: TriggerEvent,
55 _catalog: &super::CatalogReadView,
56 _resolution: &RelationNameResolution,
57 ) -> Result<bool, SQLError> {
58 self.has_instead_of_trigger(name, event)
59 }
60}
61
62pub trait CatalogNamespace: Sync {
63 fn current_schema_names(&self, include_implicit: bool) -> Result<Vec<String>, SQLError>;
64 fn current_schema_names_with_catalog(
66 &self,
67 _catalog: &super::CatalogReadView,
68 include_implicit: bool,
69 ) -> Result<Vec<String>, SQLError> {
70 self.current_schema_names(include_implicit)
71 }
72}
73
74pub trait CatalogSnapshotSource: Sync {
75 fn catalog_snapshot(&self) -> super::CatalogReadView;
76 fn builtin_routine_permissions(
78 &self,
79 current_role: RoleReference,
80 ) -> super::security::builtin_routines::execution::BuiltinRoutinePermissions {
81 super::security::builtin_routines::execution::BuiltinRoutinePermissions::new(
82 self.catalog_snapshot(),
83 current_role,
84 )
85 }
86 fn refreshed_catalog_snapshot(&self) -> Result<super::CatalogReadView, SQLError>;
87 fn refresh_catalog(&self) -> Result<(), SQLError> {
89 self.refreshed_catalog_snapshot().map(|_| ())
90 }
91 fn bind_query_reads(
93 &self,
94 snapshot: super::CatalogReadView,
95 ) -> Result<super::CatalogReadView, SQLError> {
96 Ok(snapshot)
97 }
98 fn retain_catalog_rows(
100 &self,
101 snapshot: super::CatalogReadView,
102 ) -> Result<super::CatalogReadView, SQLError> {
103 Ok(snapshot)
104 }
105 fn current_catalog_snapshot(&self) -> super::CatalogReadView;
107 fn current_catalog_revision(&self) -> Option<u64> {
109 None
110 }
111}
112impl CatalogSnapshotSource for super::CatalogReadView {
113 fn current_catalog_revision(&self) -> Option<u64> {
114 Some(0)
115 }
116 fn refresh_catalog(&self) -> Result<(), SQLError> {
117 Ok(())
118 }
119 fn current_catalog_snapshot(&self) -> super::CatalogReadView {
120 self.clone()
121 }
122 fn refreshed_catalog_snapshot(&self) -> Result<super::CatalogReadView, SQLError> {
123 Ok(self.clone())
124 }
125 fn catalog_snapshot(&self) -> super::CatalogReadView {
126 self.clone()
127 }
128}