toasty_core/stmt/
func_count.rs

1use super::{Expr, ExprFunc};
2
3#[derive(Clone, Debug, PartialEq)]
4pub struct FuncCount {
5    /// When `None`, it means `count(*)` Otherwise, count the number of rows for
6    /// which the expression does not evaluate to `NULL`
7    pub arg: Option<Box<Expr>>,
8
9    /// Optional expression used to filter the rows before counting
10    pub filter: Option<Box<Expr>>,
11}
12
13impl Expr {
14    pub fn count_star() -> Self {
15        Self::Func(ExprFunc::Count(FuncCount {
16            arg: None,
17            filter: None,
18        }))
19    }
20}
21
22impl From<FuncCount> for ExprFunc {
23    fn from(value: FuncCount) -> Self {
24        Self::Count(value)
25    }
26}
27
28impl From<FuncCount> for Expr {
29    fn from(value: FuncCount) -> Self {
30        Self::Func(value.into())
31    }
32}