toasty_core/stmt/expr_length.rs
1use super::Expr;
2
3/// Integer: number of elements in an array.
4///
5/// PostgreSQL: `cardinality(expr)`. Drives [`Path::len`](super::Path) and
6/// [`Path::is_empty`](super::Path).
7#[derive(Debug, Clone, PartialEq)]
8pub struct ExprLength {
9 /// The array whose length is being measured.
10 pub expr: Box<Expr>,
11}
12
13impl Expr {
14 /// Build an array-length expression (`cardinality(expr)` on PostgreSQL).
15 pub fn array_length(expr: impl Into<Self>) -> Self {
16 ExprLength {
17 expr: Box::new(expr.into()),
18 }
19 .into()
20 }
21}
22
23impl From<ExprLength> for Expr {
24 fn from(value: ExprLength) -> Self {
25 Self::Length(value)
26 }
27}