toasty_core/stmt/expr_all_op.rs
1use super::{BinaryOp, Expr};
2
3/// `lhs <op> ALL(rhs)` predicate against an array-valued operand.
4///
5/// Evaluates to `true` only if `lhs <op> item` holds for every `item` in
6/// `rhs`. Modeled on `sqlparser-rs`'s `AllOp`. Toasty currently lowers
7/// `NOT IN (...)` to this with [`BinaryOp::Ne`], but the operator is carried
8/// separately so the shape generalizes to other comparisons.
9#[derive(Debug, Clone, PartialEq)]
10pub struct ExprAllOp {
11 /// The scalar operand on the left.
12 pub lhs: Box<Expr>,
13
14 /// The comparison operator applied between `lhs` and each element of `rhs`.
15 pub op: BinaryOp,
16
17 /// The array-typed operand on the right (typically `Expr::Arg(n)` of
18 /// `Type::List(elem)`).
19 pub rhs: Box<Expr>,
20}
21
22impl Expr {
23 /// Creates a `lhs <op> ALL(rhs)` expression.
24 pub fn all_op(lhs: impl Into<Self>, op: BinaryOp, rhs: impl Into<Self>) -> Self {
25 ExprAllOp {
26 lhs: Box::new(lhs.into()),
27 op,
28 rhs: Box::new(rhs.into()),
29 }
30 .into()
31 }
32}
33
34impl From<ExprAllOp> for Expr {
35 fn from(value: ExprAllOp) -> Self {
36 Self::AllOp(value)
37 }
38}