drizzle_postgres/
lib.rs

1//! PostgreSQL support for drizzle-rs
2//!
3//! This crate provides PostgreSQL-specific types, query builders, and utilities.
4
5#![allow(unexpected_cfgs)]
6
7// Public modules
8pub mod attrs;
9pub mod builder;
10pub mod common;
11pub mod expressions;
12pub mod helpers;
13pub mod traits;
14pub mod values;
15
16// Re-export key types at crate root
17pub use builder::{BuilderInit, CTEInit, ExecutableState, QueryBuilder};
18pub use common::{Join, JoinType, Number, PostgresSchemaType};
19pub use traits::{
20    DrizzleRow, FromPostgresValue, PostgresColumn, PostgresColumnInfo, PostgresEnum, PostgresTable,
21    PostgresTableInfo,
22};
23pub use values::{PostgresInsertValue, PostgresValue, ValueWrapper};
24
25// Re-export Row type from the active postgres driver
26#[cfg(all(feature = "postgres-sync", not(feature = "tokio-postgres")))]
27pub use postgres::Row;
28#[cfg(feature = "tokio-postgres")]
29pub use tokio_postgres::Row;
30
31// Re-export ParamBind for use in params! macro
32pub use drizzle_core::ParamBind;
33
34// Type alias for convenience
35pub type PostgresSQL<'a> = drizzle_core::SQL<'a, PostgresValue<'a>>;
36
37/// PostgreSQL transaction isolation levels
38#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
39pub enum PostgresTransactionType {
40    /// READ UNCOMMITTED isolation level
41    ReadUncommitted,
42    /// READ COMMITTED isolation level (PostgreSQL default)
43    #[default]
44    ReadCommitted,
45    /// REPEATABLE READ isolation level
46    RepeatableRead,
47    /// SERIALIZABLE isolation level
48    Serializable,
49}
50
51impl std::fmt::Display for PostgresTransactionType {
52    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
53        let level = match self {
54            PostgresTransactionType::ReadUncommitted => "READ UNCOMMITTED",
55            PostgresTransactionType::ReadCommitted => "READ COMMITTED",
56            PostgresTransactionType::RepeatableRead => "REPEATABLE READ",
57            PostgresTransactionType::Serializable => "SERIALIZABLE",
58        };
59        write!(f, "{}", level)
60    }
61}
62
63/// Creates an array of SQL parameters for binding values to placeholders.
64///
65/// # Syntax
66/// - `{ name: value }` - Named parameter (creates :name placeholder)
67///
68/// # Examples
69///
70/// ```
71/// use drizzle_postgres::params;
72///
73/// let params = params![{ name: "alice" }, { active: true }];
74/// ```
75#[macro_export]
76macro_rules! params {
77    [$($param:tt),+ $(,)?] => {
78        [
79            $(
80                $crate::params_internal!($param)
81            ),+
82        ]
83    };
84}
85
86/// Internal helper macro for params!
87#[macro_export]
88macro_rules! params_internal {
89    ({ $key:ident: $value:expr }) => {
90        $crate::ParamBind::named(stringify!($key), $crate::PostgresValue::from($value))
91    };
92    ($value:expr) => {
93        $crate::ParamBind::positional($crate::PostgresValue::from($value))
94    };
95}