drizzle_sqlite/traits/
column.rs

1use drizzle_core::{SQLColumn, SQLColumnInfo};
2
3use crate::{SQLiteValue, traits::SQLiteTableInfo};
4
5pub trait SQLiteColumn<'a>: SQLColumn<'a, SQLiteValue<'a>> {
6    const AUTOINCREMENT: bool = false;
7}
8
9pub trait SQLiteColumnInfo: SQLColumnInfo {
10    fn is_autoincrement(&self) -> bool;
11    fn table(&self) -> &dyn SQLiteTableInfo;
12
13    /// Returns the foreign key reference if this column has one
14    fn foreign_key(&self) -> Option<&'static dyn SQLiteColumnInfo> {
15        None
16    }
17}
18
19pub trait AsColumnInfo: SQLColumnInfo {
20    fn as_column(&self) -> &dyn SQLiteColumnInfo;
21}
22
23impl<T: SQLiteColumnInfo> AsColumnInfo for T {
24    fn as_column(&self) -> &dyn SQLiteColumnInfo {
25        self
26    }
27}
28
29impl std::fmt::Debug for dyn SQLiteColumnInfo {
30    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
31        f.debug_struct("SQLiteColumnInfo")
32            .field("name", &self.name())
33            .field("type", &self.r#type())
34            .field("not_null", &self.is_not_null())
35            .field("primary_key", &self.is_primary_key())
36            .field("unique", &self.is_unique())
37            .field("table", &SQLiteColumnInfo::table(self))
38            .field("has_default", &self.has_default())
39            .field("is_autoincrement", &self.is_autoincrement())
40            .finish()
41    }
42}