drizzle_postgres/
lib.rs

1//! PostgreSQL support for drizzle-rs
2//!
3//! This crate provides PostgreSQL-specific types, query builders, and utilities
4//! for the drizzle-rs ORM. It supports runtime-agnostic database connections
5//! through optional sqlx integration.
6
7// Re-export common types and traits
8pub use drizzle_core::{OrderBy, SQL, ToSQL};
9
10// Re-export PostgreSQL-specific modules
11pub mod builder;
12pub mod common;
13pub mod helpers;
14pub mod traits;
15pub mod values;
16
17// Re-export key types for easier access
18pub use builder::{BuilderInit, BuilderState, CTEInit, ExecutableState, QueryBuilder};
19pub use common::{Join, JoinType, Number, PostgresSchemaType};
20pub use traits::{PostgresColumn, PostgresColumnInfo, PostgresEnum};
21pub use values::{PostgresInsertValue, PostgresValue, ValueWrapper};
22
23// Transaction types - PostgreSQL specific isolation levels
24#[derive(Debug, Clone, Copy, PartialEq, Eq)]
25pub enum PostgresTransactionType {
26    /// READ UNCOMMITTED isolation level
27    ReadUncommitted,
28    /// READ COMMITTED isolation level (PostgreSQL default)
29    ReadCommitted,
30    /// REPEATABLE READ isolation level
31    RepeatableRead,
32    /// SERIALIZABLE isolation level
33    Serializable,
34}
35
36impl Default for PostgresTransactionType {
37    fn default() -> Self {
38        Self::ReadCommitted
39    }
40}
41
42impl std::fmt::Display for PostgresTransactionType {
43    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
44        let level = match self {
45            PostgresTransactionType::ReadUncommitted => "READ UNCOMMITTED",
46            PostgresTransactionType::ReadCommitted => "READ COMMITTED",
47            PostgresTransactionType::RepeatableRead => "REPEATABLE READ",
48            PostgresTransactionType::Serializable => "SERIALIZABLE",
49        };
50        write!(f, "{}", level)
51    }
52}
53
54pub type PostgresSQL<'a> = SQL<'a, PostgresValue<'a>>;
55
56pub trait ToPostgresSQL<'a>: ToSQL<'a, PostgresValue<'a>> {
57    fn to_pg_sql(&self) -> PostgresSQL<'a> {
58        self.to_sql()
59    }
60}
61impl<'a, T: ToSQL<'a, PostgresValue<'a>>> ToPostgresSQL<'a> for T {}