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 postgres_columns(&self) -> &'static [&'static dyn PostgresColumnInfo];
13
14 fn postgres_dependencies(&self) -> &'static [&'static dyn PostgresTableInfo];
16}
17
18impl<T: PostgresTableInfo> PostgresTableInfo for &'static T {
20 fn r#type(&self) -> &PostgresSchemaType {
21 (*self).r#type()
22 }
23
24 fn postgres_columns(&self) -> &'static [&'static dyn PostgresColumnInfo] {
25 (*self).postgres_columns()
26 }
27
28 fn postgres_dependencies(&self) -> &'static [&'static dyn PostgresTableInfo] {
29 (*self).postgres_dependencies()
30 }
31}
32
33impl std::fmt::Debug for dyn PostgresTableInfo {
34 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
35 f.debug_struct("PostgresTableInfo")
36 .field("name", &self.name())
37 .field("type", &self.r#type())
38 .field("columns", &PostgresTableInfo::postgres_columns(self))
39 .field(
40 "dependencies",
41 &PostgresTableInfo::postgres_dependencies(self),
42 )
43 .finish()
44 }
45}