use drizzle_core::{SQLColumn, SQLColumnInfo};
use crate::traits::SQLiteTableInfo;
use crate::values::SQLiteValue;
pub trait SQLiteColumn<'a>: SQLColumn<'a, SQLiteValue<'a>> {
const AUTOINCREMENT: bool = false;
}
pub trait SQLiteColumnInfo: SQLColumnInfo {
fn is_autoincrement(&self) -> bool;
fn table(&self) -> &dyn SQLiteTableInfo;
fn foreign_key(&self) -> Option<&'static dyn SQLiteColumnInfo> {
None
}
fn as_sqlite_column(&self) -> &dyn SQLiteColumnInfo
where
Self: Sized,
{
self
}
fn foreign_key_core(&self) -> Option<&'static dyn SQLColumnInfo> {
<Self as SQLiteColumnInfo>::foreign_key(self).map(|fk| fk as &dyn SQLColumnInfo)
}
}
impl<T: SQLiteColumnInfo> SQLiteColumnInfo for &'static T {
fn is_autoincrement(&self) -> bool {
<T as SQLiteColumnInfo>::is_autoincrement(*self)
}
fn table(&self) -> &dyn SQLiteTableInfo {
<T as SQLiteColumnInfo>::table(*self)
}
fn foreign_key(&self) -> Option<&'static dyn SQLiteColumnInfo> {
<T as SQLiteColumnInfo>::foreign_key(*self)
}
}
impl std::fmt::Debug for dyn SQLiteColumnInfo {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("SQLiteColumnInfo")
.field("name", &self.name())
.field("type", &self.r#type())
.field("not_null", &self.is_not_null())
.field("primary_key", &self.is_primary_key())
.field("unique", &self.is_unique())
.field("table", &SQLiteColumnInfo::table(self))
.field("has_default", &self.has_default())
.field("is_autoincrement", &self.is_autoincrement())
.finish()
}
}