use core::any::Any;
use crate::{SQLParam, SQLSchemaType, SQLTable, SQLTableInfo, ToSQL};
pub trait SQLIndexInfo: Any + Send + Sync {
fn table(&self) -> &dyn SQLTableInfo;
fn name(&self) -> &'static str;
fn columns(&self) -> &'static [&'static str];
fn is_unique(&self) -> bool {
false
}
}
pub trait AsIndexInfo: Sized + SQLIndexInfo {
fn as_index(&self) -> &dyn SQLIndexInfo {
self
}
}
impl core::fmt::Debug for dyn SQLIndexInfo {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.debug_struct("SQLIndexInfo")
.field("name", &self.name())
.field("is_unique", &self.is_unique())
.field("columns", &self.columns())
.field("table", &self.table())
.finish()
}
}
pub trait SQLIndex<'a, Type: SQLSchemaType, Value: SQLParam + 'a>:
SQLIndexInfo + ToSQL<'a, Value>
{
type Table: SQLTable<'a, Type, Value>;
}