Skip to main content

fraiseql_db/postgres/
where_generator.rs

1//! PostgreSQL WHERE clause SQL generation.
2//!
3//! `PostgresWhereGenerator` is a type alias for
4//! `GenericWhereGenerator<PostgresDialect>`.  All logic lives in
5//! [`crate::where_generator::GenericWhereGenerator`].
6
7use crate::{dialect::PostgresDialect, where_generator::GenericWhereGenerator};
8
9/// PostgreSQL WHERE clause generator.
10///
11/// Type alias for `GenericWhereGenerator<PostgresDialect>`.
12/// Refer to [`GenericWhereGenerator`] for full documentation.
13///
14/// # Example
15///
16/// ```rust
17/// use fraiseql_db::postgres::PostgresWhereGenerator;
18/// use fraiseql_db::{WhereClause, WhereOperator};
19/// use serde_json::json;
20///
21/// let generator = PostgresWhereGenerator::postgres_new();
22///
23/// let clause = WhereClause::Field {
24///     path: vec!["email".to_string()],
25///     operator: WhereOperator::Icontains,
26///     value: json!("example.com"),
27/// };
28///
29/// let (sql, params) = generator.generate(&clause).expect("Failed to generate SQL");
30/// // sql: "data->>'email' ILIKE '%' || $1 || '%'"
31/// ```
32pub type PostgresWhereGenerator = GenericWhereGenerator<PostgresDialect>;
33
34/// Constructor compatibility shim for `PostgresWhereGenerator`.
35///
36/// This `impl` block exposes the `new()` constructor the old concrete struct had.
37impl PostgresWhereGenerator {
38    /// Create a new PostgreSQL WHERE generator.
39    #[must_use]
40    pub const fn postgres_new() -> Self {
41        Self::new(PostgresDialect)
42    }
43}
44
45#[cfg(test)]
46mod tests;