drizzle_sqlite/traits/
table.rs

1use drizzle_core::{SQLTable, SQLTableInfo};
2
3use crate::{SQLiteValue, common::SQLiteSchemaType, traits::SQLiteColumnInfo};
4
5pub trait SQLiteTable<'a>:
6    SQLTable<'a, SQLiteSchemaType, SQLiteValue<'a>> + SQLiteTableInfo
7{
8    const WITHOUT_ROWID: bool;
9    const STRICT: bool;
10}
11
12pub trait SQLiteTableInfo: SQLTableInfo {
13    fn r#type(&self) -> &SQLiteSchemaType;
14    fn without_rowid(&self) -> bool;
15    fn strict(&self) -> bool;
16
17    fn columns(&self) -> Box<[&'static dyn SQLiteColumnInfo]>;
18
19    /// Returns all tables this table depends on via foreign keys
20    fn dependencies(&self) -> Box<[&'static dyn SQLiteTableInfo]> {
21        SQLiteTableInfo::columns(self)
22            .iter()
23            .filter_map(|&col| SQLiteColumnInfo::foreign_key(col))
24            .map(|fk_col| SQLiteColumnInfo::table(fk_col))
25            .collect()
26    }
27}
28
29impl std::fmt::Debug for dyn SQLiteTableInfo {
30    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
31        f.debug_struct("SQLiteTableInfo")
32            .field("name", &self.name())
33            .field("type", &self.r#type())
34            .field("columns", &SQLiteTableInfo::columns(self))
35            .field("without_rowid", &self.without_rowid())
36            .field("strict", &self.strict())
37            .field("dependencies", &SQLiteTableInfo::dependencies(self))
38            .finish()
39    }
40}