drizzle_postgres/
traits.rs1mod column;
2mod table;
3mod value;
4
5#[cfg(not(feature = "std"))]
6use crate::prelude::*;
7pub use column::*;
8use core::any::Any;
9use drizzle_core::error::DrizzleError;
10pub use table::*;
11pub use value::*;
12
13use crate::values::PostgresValue;
14
15#[allow(clippy::wrong_self_convention)]
17pub trait PostgresEnum: Send + Sync + Any {
18 fn enum_type_name(&self) -> &'static str;
20
21 fn as_enum(&self) -> &dyn PostgresEnum;
22
23 fn variant_name(&self) -> &'static str;
25
26 fn into_boxed(&self) -> Box<dyn PostgresEnum>;
28
29 fn try_from_str(value: &str) -> Result<Self, DrizzleError>
36 where
37 Self: Sized;
38}
39
40impl core::fmt::Debug for &dyn PostgresEnum {
41 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
42 f.debug_struct("PostgresSQLEnum")
43 .field("type", &self.enum_type_name())
44 .field("variant", &self.variant_name())
45 .finish()
46 }
47}
48
49impl PartialEq for &dyn PostgresEnum {
50 fn eq(&self, other: &Self) -> bool {
51 self.enum_type_name() == other.enum_type_name()
52 && self.variant_name() == other.variant_name()
53 }
54}
55
56impl core::fmt::Debug for Box<dyn PostgresEnum> {
57 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
58 f.debug_struct("PostgresSQLEnum")
59 .field("type", &self.enum_type_name())
60 .field("variant", &self.variant_name())
61 .finish()
62 }
63}
64
65impl Clone for Box<dyn PostgresEnum> {
66 fn clone(&self) -> Self {
67 self.into_boxed()
68 }
69}
70
71impl PartialEq for Box<dyn PostgresEnum> {
72 fn eq(&self, other: &Self) -> bool {
73 self.enum_type_name() == other.enum_type_name()
74 && self.variant_name() == other.variant_name()
75 }
76}
77
78#[cfg(any(feature = "postgres-sync", feature = "tokio-postgres"))]
93#[diagnostic::on_unimplemented(
94 message = "`{Self}` cannot be used as a PostgreSQL column type",
95 note = "add #[derive(PostgresEnum)] for enum types, or use a supported primitive type"
96)]
97pub trait DrizzlePostgresColumn: Sized {
98 const SQL_TYPE: &'static str;
100
101 const NEEDS_CREATE_TYPE: bool = false;
103
104 fn from_postgres_row(row: &crate::Row, idx: usize) -> Result<Self, DrizzleError>;
111
112 fn to_postgres_value(&self) -> PostgresValue<'static>;
114}
115
116#[cfg(not(any(feature = "postgres-sync", feature = "tokio-postgres")))]
119#[diagnostic::on_unimplemented(
120 message = "`{Self}` cannot be used as a PostgreSQL column type",
121 note = "add #[derive(PostgresEnum)] for enum types, or use a supported primitive type"
122)]
123pub trait DrizzlePostgresColumn: Sized {
124 const SQL_TYPE: &'static str;
126
127 const NEEDS_CREATE_TYPE: bool = false;
129
130 fn to_postgres_value(&self) -> PostgresValue<'static>;
132}