drizzle_core/traits/
view.rs1use crate::prelude::Cow;
2use crate::traits::SQLSchemaType;
3use crate::{SQL, SQLParam, SQLTable, SQLTableInfo};
4use core::any::Any;
5
6#[diagnostic::on_unimplemented(
10 message = "`{Self}` is not a SQL view for this dialect",
11 label = "ensure this type was derived with a drizzle view macro"
12)]
13pub trait SQLView<'a, Type: SQLSchemaType, Value: SQLParam + 'a>:
14 SQLTable<'a, Type, Value>
15{
16 fn definition(&self) -> SQL<'a, Value>;
18
19 fn is_existing(&self) -> bool {
22 false
23 }
24}
25
26pub trait SQLViewInfo: SQLTableInfo + Any {
28 fn definition_sql(&self) -> Cow<'static, str>;
30
31 fn is_existing(&self) -> bool {
34 false
35 }
36
37 fn is_materialized(&self) -> bool {
39 false
40 }
41
42 fn with_no_data(&self) -> Option<bool> {
44 None
45 }
46
47 fn using_clause(&self) -> Option<&'static str> {
49 None
50 }
51
52 fn tablespace(&self) -> Option<&'static str> {
54 None
55 }
56}
57
58impl core::fmt::Debug for dyn SQLViewInfo {
59 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
60 f.debug_struct("SQLViewInfo")
61 .field("name", &self.name())
62 .field("schema", &SQLTableInfo::schema(self))
63 .field("qualified_name", &SQLTableInfo::qualified_name(self))
64 .field("definition", &self.definition_sql())
65 .field("existing", &self.is_existing())
66 .field("materialized", &self.is_materialized())
67 .finish()
68 }
69}