use crate::prelude::Cow;
use crate::traits::SQLSchemaType;
use crate::{SQL, SQLParam, SQLTable, SQLTableInfo};
use core::any::Any;
pub trait SQLView<'a, Type: SQLSchemaType, Value: SQLParam + 'a>:
SQLTable<'a, Type, Value>
{
fn definition(&self) -> SQL<'a, Value>;
fn is_existing(&self) -> bool {
false
}
}
pub trait SQLViewInfo: SQLTableInfo + Any {
fn definition_sql(&self) -> Cow<'static, str>;
fn is_existing(&self) -> bool {
false
}
fn is_materialized(&self) -> bool {
false
}
fn with_no_data(&self) -> Option<bool> {
None
}
fn using_clause(&self) -> Option<&'static str> {
None
}
fn tablespace(&self) -> Option<&'static str> {
None
}
fn as_view_info(&self) -> &dyn SQLViewInfo
where
Self: Sized,
{
self
}
}
impl core::fmt::Debug for dyn SQLViewInfo {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.debug_struct("SQLViewInfo")
.field("name", &self.name())
.field("schema", &SQLTableInfo::schema(self))
.field("qualified_name", &SQLTableInfo::qualified_name(self))
.field("definition", &self.definition_sql())
.field("existing", &self.is_existing())
.field("materialized", &self.is_materialized())
.finish()
}
}