dbkit_core/
func.rs

1use crate::expr::{Expr, ExprNode, IntoExpr};
2
3pub fn upper(arg: impl IntoExpr<String>) -> Expr<String> {
4    let expr = arg.into_expr();
5    Expr::new(ExprNode::Func {
6        name: "UPPER",
7        args: vec![expr.node],
8    })
9}
10
11pub fn count<T>(arg: impl IntoExpr<T>) -> Expr<i64> {
12    let expr = arg.into_expr();
13    Expr::new(ExprNode::Func {
14        name: "COUNT",
15        args: vec![expr.node],
16    })
17}
18
19pub fn sum<T>(arg: impl IntoExpr<T>) -> Expr<T> {
20    let expr = arg.into_expr();
21    Expr::new(ExprNode::Func {
22        name: "SUM",
23        args: vec![expr.node],
24    })
25}
26
27pub fn coalesce<T>(a: impl IntoExpr<T>, b: impl IntoExpr<T>) -> Expr<T> {
28    let left = a.into_expr();
29    let right = b.into_expr();
30    Expr::new(ExprNode::Func {
31        name: "COALESCE",
32        args: vec![left.node, right.node],
33    })
34}
35
36pub fn date_trunc<T>(part: impl IntoExpr<String>, value: impl IntoExpr<T>) -> Expr<T> {
37    let part = part.into_expr();
38    let value = value.into_expr();
39    Expr::new(ExprNode::Func {
40        name: "DATE_TRUNC",
41        args: vec![part.node, value.node],
42    })
43}