drizzle_postgres/traits/
table.rs1use drizzle_core::{SQLTable, SQLTableInfo};
2
3use crate::{PostgresColumnInfo, PostgresValue, common::PostgresSchemaType};
4
5pub trait PostgresTable<'a>:
6 SQLTable<'a, PostgresSchemaType, PostgresValue<'a>> + PostgresTableInfo
7{
8}
9
10pub trait PostgresTableInfo: SQLTableInfo {
11 fn r#type(&self) -> &PostgresSchemaType;
12 fn columns(&self) -> Box<[&'static dyn PostgresColumnInfo]>;
13
14 fn dependencies(&self) -> Box<[&'static dyn PostgresTableInfo]> {
16 PostgresTableInfo::columns(self)
17 .iter()
18 .filter_map(|&col| PostgresColumnInfo::foreign_key(col))
19 .map(|fk_col| PostgresColumnInfo::table(fk_col))
20 .collect()
21 }
22}
23
24impl std::fmt::Debug for dyn PostgresTableInfo {
25 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
26 f.debug_struct("PostgresTableInfo")
27 .field("name", &self.name())
28 .field("type", &self.r#type())
29 .field("columns", &PostgresTableInfo::columns(self))
30 .field("dependencies", &PostgresTableInfo::dependencies(self))
31 .finish()
32 }
33}