drizzle_core/traits/
view.rs1use crate::prelude::Cow;
2use crate::traits::SQLSchemaType;
3use crate::{SQL, SQLParam, SQLTable, SQLTableInfo};
4use core::any::Any;
5
6pub trait SQLView<'a, Type: SQLSchemaType, Value: SQLParam + 'a>:
10 SQLTable<'a, Type, Value>
11{
12 fn definition(&self) -> SQL<'a, Value>;
14
15 fn is_existing(&self) -> bool {
17 false
18 }
19}
20
21pub trait SQLViewInfo: SQLTableInfo + Any {
23 fn definition_sql(&self) -> Cow<'static, str>;
25
26 fn is_existing(&self) -> bool {
28 false
29 }
30
31 fn is_materialized(&self) -> bool {
33 false
34 }
35
36 fn with_no_data(&self) -> Option<bool> {
38 None
39 }
40
41 fn using_clause(&self) -> Option<&'static str> {
43 None
44 }
45
46 fn tablespace(&self) -> Option<&'static str> {
48 None
49 }
50
51 fn as_view_info(&self) -> &dyn SQLViewInfo
53 where
54 Self: Sized,
55 {
56 self
57 }
58}
59
60impl core::fmt::Debug for dyn SQLViewInfo {
61 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
62 f.debug_struct("SQLViewInfo")
63 .field("name", &self.name())
64 .field("schema", &SQLTableInfo::schema(self))
65 .field("qualified_name", &SQLTableInfo::qualified_name(self))
66 .field("definition", &self.definition_sql())
67 .field("existing", &self.is_existing())
68 .field("materialized", &self.is_materialized())
69 .finish()
70 }
71}