Skip to main content

drizzle_postgres/
common.rs

1use drizzle_core::schema::SQLEnumInfo;
2use drizzle_core::traits::SQLViewInfo;
3use drizzle_core::{SQLIndexInfo, SQLPolicyInfo, SQLSchemaType};
4
5/// The type of database object
6#[derive(Debug, Clone)]
7pub enum PostgresSchemaType {
8    /// A regular table
9    Table(&'static drizzle_core::TableRef),
10    /// A view
11    View(&'static dyn SQLViewInfo),
12    /// An index
13    Index(&'static dyn SQLIndexInfo),
14    /// A row-level security policy
15    Policy(&'static dyn SQLPolicyInfo),
16    /// A trigger
17    Trigger,
18    /// A database enum type (`PostgreSQL`)
19    Enum(&'static dyn SQLEnumInfo),
20}
21
22impl SQLSchemaType for PostgresSchemaType {}
23
24//------------------------------------------------------------------------------
25// Number Type
26//------------------------------------------------------------------------------
27
28/// Numeric type that can be either an integer or a floating point value
29#[derive(Clone, Copy, Debug, PartialEq, PartialOrd)]
30pub enum Number {
31    /// Integer value
32    Integer(i64),
33    /// Floating point value
34    Real(f64),
35}
36
37impl Default for Number {
38    fn default() -> Self {
39        Self::Integer(Default::default())
40    }
41}
42
43impl From<i64> for Number {
44    fn from(value: i64) -> Self {
45        Self::Integer(value)
46    }
47}
48
49impl From<f64> for Number {
50    fn from(value: f64) -> Self {
51        Self::Real(value)
52    }
53}
54
55/// `PostgreSQL` transaction isolation levels
56#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
57pub enum PostgresTransactionType {
58    /// READ UNCOMMITTED isolation level
59    ReadUncommitted,
60    /// READ COMMITTED isolation level (`PostgreSQL` default)
61    #[default]
62    ReadCommitted,
63    /// REPEATABLE READ isolation level
64    RepeatableRead,
65    /// SERIALIZABLE isolation level
66    Serializable,
67}
68
69impl core::fmt::Display for PostgresTransactionType {
70    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
71        let level = match self {
72            Self::ReadUncommitted => "READ UNCOMMITTED",
73            Self::ReadCommitted => "READ COMMITTED",
74            Self::RepeatableRead => "REPEATABLE READ",
75            Self::Serializable => "SERIALIZABLE",
76        };
77        write!(f, "{level}")
78    }
79}
80
81// Note: Generic From implementation is removed to avoid conflicts.
82// The table macro will generate specific implementations using PostgresEnumVisitor.
83
84// Re-export Join from core
85pub use drizzle_core::{Join, JoinType};