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 schema(&self) -> &'static str {
28 "public"
29 }
30
31 fn is_existing(&self) -> bool {
33 false
34 }
35
36 fn is_materialized(&self) -> bool {
38 false
39 }
40
41 fn with_no_data(&self) -> Option<bool> {
43 None
44 }
45
46 fn using_clause(&self) -> Option<&'static str> {
48 None
49 }
50
51 fn tablespace(&self) -> Option<&'static str> {
53 None
54 }
55
56 fn as_view_info(&self) -> &dyn SQLViewInfo
58 where
59 Self: Sized,
60 {
61 self
62 }
63}
64
65impl core::fmt::Debug for dyn SQLViewInfo {
66 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
67 f.debug_struct("SQLViewInfo")
68 .field("name", &self.name())
69 .field("schema", &self.schema())
70 .field("definition", &self.definition_sql())
71 .field("existing", &self.is_existing())
72 .field("materialized", &self.is_materialized())
73 .finish()
74 }
75}