toasty_core/stmt/
expr_is_null.rs

1use super::Expr;
2
3/// Tests whether an expression is null.
4///
5/// Returns `true` if the expression evaluates to null.
6///
7/// # Examples
8///
9/// ```text
10/// is_null(x)      // returns `true` if x is null
11/// is_not_null(x)  // returns `true` if x is not null
12/// ```
13#[derive(Debug, Clone, PartialEq)]
14pub struct ExprIsNull {
15    /// The expression to check for null.
16    pub expr: Box<Expr>,
17}
18
19impl Expr {
20    /// Creates an `IS NULL` expression.
21    pub fn is_null(expr: impl Into<Self>) -> Self {
22        ExprIsNull {
23            expr: Box::new(expr.into()),
24        }
25        .into()
26    }
27
28    /// Creates an `IS NOT NULL` expression (equivalent to `NOT(IS NULL(expr))`).
29    pub fn is_not_null(expr: impl Into<Self>) -> Self {
30        Self::not(Self::is_null(expr))
31    }
32}
33
34impl From<ExprIsNull> for Expr {
35    fn from(value: ExprIsNull) -> Self {
36        Self::IsNull(value)
37    }
38}