drizzle_postgres/expressions.rs
1//! PostgreSQL-specific expressions
2//!
3//! This module provides PostgreSQL dialect-specific SQL expressions.
4//! For standard SQL expressions, use `drizzle_core::expressions`.
5
6use crate::{PostgresSQL, PostgresValue};
7use drizzle_core::traits::ToSQL;
8
9/// Case-insensitive LIKE pattern matching (PostgreSQL-specific)
10///
11/// # Example
12///
13/// ```ignore
14/// use drizzle::postgres::expressions::ilike;
15///
16/// let query = ilike(user.name, "%john%");
17/// // Generates: "name" ILIKE '%john%'
18/// ```
19pub fn ilike<'a, L, R>(left: L, pattern: R) -> PostgresSQL<'a>
20where
21 L: ToSQL<'a, PostgresValue<'a>>,
22 R: Into<PostgresValue<'a>> + ToSQL<'a, PostgresValue<'a>>,
23{
24 use drizzle_core::sql::SQLChunk;
25 left.to_sql()
26 .push(SQLChunk::Raw("ILIKE".into()))
27 .append(pattern.to_sql())
28}
29
30/// Case-insensitive NOT LIKE pattern matching (PostgreSQL-specific)
31///
32/// # Example
33///
34/// ```ignore
35/// use drizzle::postgres::expressions::not_ilike;
36///
37/// let query = not_ilike(user.name, "%admin%");
38/// // Generates: "name" NOT ILIKE '%admin%'
39/// ```
40pub fn not_ilike<'a, L, R>(left: L, pattern: R) -> PostgresSQL<'a>
41where
42 L: ToSQL<'a, PostgresValue<'a>>,
43 R: Into<PostgresValue<'a>> + ToSQL<'a, PostgresValue<'a>>,
44{
45 use drizzle_core::sql::{SQLChunk, Token};
46 left.to_sql()
47 .push(Token::NOT)
48 .push(SQLChunk::Raw("ILIKE".into()))
49 .append(pattern.to_sql())
50}