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