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 {
21 false
22 }
23}
24
25pub trait SQLViewInfo: SQLTableInfo + Any {
27 fn definition_sql(&self) -> Cow<'static, str>;
29
30 fn is_existing(&self) -> bool {
32 false
33 }
34
35 fn is_materialized(&self) -> bool {
37 false
38 }
39
40 fn with_no_data(&self) -> Option<bool> {
42 None
43 }
44
45 fn using_clause(&self) -> Option<&'static str> {
47 None
48 }
49
50 fn tablespace(&self) -> Option<&'static str> {
52 None
53 }
54}
55
56impl core::fmt::Debug for dyn SQLViewInfo {
57 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
58 f.debug_struct("SQLViewInfo")
59 .field("name", &self.name())
60 .field("schema", &SQLTableInfo::schema(self))
61 .field("qualified_name", &SQLTableInfo::qualified_name(self))
62 .field("definition", &self.definition_sql())
63 .field("existing", &self.is_existing())
64 .field("materialized", &self.is_materialized())
65 .finish()
66 }
67}