grafbase_sql_ast/ast/function/
count.rs

1use super::Function;
2use crate::ast::{Expression, FunctionType};
3
4#[derive(Debug, Clone, PartialEq)]
5/// Returns the number of rows that matches a specified criteria.
6pub struct Count<'a> {
7    pub(crate) exprs: Vec<Expression<'a>>,
8}
9
10/// Count of the underlying table where the given expression is not null.
11pub fn count<'a, T>(expr: T) -> Function<'a>
12where
13    T: Into<Expression<'a>>,
14{
15    let fun = Count {
16        exprs: vec![expr.into()],
17    };
18
19    fun.into()
20}
21
22impl<'a> From<Count<'a>> for Function<'a> {
23    fn from(value: Count<'a>) -> Self {
24        Self {
25            typ_: FunctionType::Count(value),
26            alias: None,
27        }
28    }
29}