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 sqlite_columns(&self) -> &'static [&'static dyn SQLiteColumnInfo];
18
19    /// Returns all tables this table depends on via foreign keys
20    fn sqlite_dependencies(&self) -> &'static [&'static dyn SQLiteTableInfo];
21}
22
23// Blanket implementation for static references
24impl<T: SQLiteTableInfo> SQLiteTableInfo for &'static T {
25    fn r#type(&self) -> &SQLiteSchemaType {
26        (*self).r#type()
27    }
28
29    fn without_rowid(&self) -> bool {
30        (*self).without_rowid()
31    }
32
33    fn strict(&self) -> bool {
34        (*self).strict()
35    }
36
37    fn sqlite_columns(&self) -> &'static [&'static dyn SQLiteColumnInfo] {
38        (*self).sqlite_columns()
39    }
40
41    fn sqlite_dependencies(&self) -> &'static [&'static dyn SQLiteTableInfo] {
42        (*self).sqlite_dependencies()
43    }
44}
45
46impl std::fmt::Debug for dyn SQLiteTableInfo {
47    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
48        f.debug_struct("SQLiteTableInfo")
49            .field("name", &self.name())
50            .field("type", &self.r#type())
51            .field("columns", &SQLiteTableInfo::sqlite_columns(self))
52            .field("without_rowid", &self.without_rowid())
53            .field("strict", &self.strict())
54            .field("dependencies", &SQLiteTableInfo::sqlite_dependencies(self))
55            .finish()
56    }
57}