gluesql_core/data/
function.rs

1use {
2    crate::ast::{Expr, OperateFunctionArg},
3    serde::{Deserialize, Serialize},
4};
5
6#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
7pub struct CustomFunction {
8    pub func_name: String,
9    pub args: Vec<OperateFunctionArg>,
10    pub body: Expr,
11}
12
13impl CustomFunction {
14    pub fn to_str(&self) -> String {
15        let name = &self.func_name;
16        let args = self
17            .args
18            .iter()
19            .map(|arg| format!("{}: {}", arg.name, arg.data_type))
20            .collect::<Vec<String>>()
21            .join(", ");
22        format!("{name}({args})")
23    }
24}