toasty_core/stmt/expr_any_op.rs
1use super::{BinaryOp, Expr};
2
3/// `lhs <op> ANY(rhs)` predicate against an array-valued operand.
4///
5/// Evaluates to `true` if `lhs <op> item` holds for any `item` in `rhs`.
6/// Modeled on `sqlparser-rs`'s `AnyOp`. Toasty currently lowers `IN (...)` to
7/// this with [`BinaryOp::Eq`], but the operator is carried separately so the
8/// shape generalizes to other comparisons.
9#[derive(Debug, Clone, PartialEq)]
10pub struct ExprAnyOp {
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> ANY(rhs)` expression.
24 pub fn any_op(lhs: impl Into<Self>, op: BinaryOp, rhs: impl Into<Self>) -> Self {
25 ExprAnyOp {
26 lhs: Box::new(lhs.into()),
27 op,
28 rhs: Box::new(rhs.into()),
29 }
30 .into()
31 }
32}
33
34impl From<ExprAnyOp> for Expr {
35 fn from(value: ExprAnyOp) -> Self {
36 Self::AnyOp(value)
37 }
38}