quaint_forked/ast/function/count.rs
1use super::Function;
2use crate::ast::Expression;
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.
11///
12/// ```rust
13/// # use quaint::{ast::*, visitor::{Visitor, Sqlite}};
14/// # fn main() -> Result<(), quaint::error::Error> {
15/// let query = Select::from_table("users").value(count(asterisk()));
16/// let (sql, _) = Sqlite::build(query)?;
17/// assert_eq!("SELECT COUNT(*) FROM `users`", sql);
18/// # Ok(())
19/// # }
20/// ```
21pub fn count<'a, T>(expr: T) -> Function<'a>
22where
23 T: Into<Expression<'a>>,
24{
25 let fun = Count {
26 exprs: vec![expr.into()],
27 };
28
29 fun.into()
30}