grafbase_sql_ast/ast/function/
aggregate_to_string.rs

1use super::Function;
2use crate::ast::{Expression, FunctionType};
3
4#[derive(Debug, Clone, PartialEq)]
5/// An aggregate function that concatenates strings from a group into a single
6/// string with various options.
7pub struct AggregateToString<'a> {
8    pub(crate) value: Box<Expression<'a>>,
9}
10
11/// Aggregates the given field into a string.
12pub fn aggregate_to_string<'a, T>(expr: T) -> Function<'a>
13where
14    T: Into<Expression<'a>>,
15{
16    let fun = AggregateToString {
17        value: Box::new(expr.into()),
18    };
19
20    fun.into()
21}
22
23impl<'a> From<AggregateToString<'a>> for Function<'a> {
24    fn from(value: AggregateToString<'a>) -> Self {
25        Self {
26            typ_: FunctionType::AggregateToString(value),
27            alias: None,
28        }
29    }
30}