Skip to main content

toasty_core/stmt/
expr_is_superset.rs

1use super::Expr;
2
3/// Boolean: `lhs` (array) contains every element of `rhs` (array).
4///
5/// PostgreSQL: `lhs @> rhs`. Drives [`Path::is_superset`](super::Path).
6#[derive(Debug, Clone, PartialEq)]
7pub struct ExprIsSuperset {
8    /// The array claimed to be the superset.
9    pub lhs: Box<Expr>,
10    /// The array claimed to be the subset.
11    pub rhs: Box<Expr>,
12}
13
14impl Expr {
15    /// Build an `IsSuperset` array predicate (`lhs @> rhs` on PostgreSQL).
16    pub fn array_is_superset(lhs: impl Into<Self>, rhs: impl Into<Self>) -> Self {
17        ExprIsSuperset {
18            lhs: Box::new(lhs.into()),
19            rhs: Box::new(rhs.into()),
20        }
21        .into()
22    }
23}
24
25impl From<ExprIsSuperset> for Expr {
26    fn from(value: ExprIsSuperset) -> Self {
27        Self::IsSuperset(value)
28    }
29}