Skip to main content

drizzle_postgres/
common.rs

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