zen_engine/handler/table/
mod.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
pub mod zen;

use zen_expression::variable::Variable;

#[derive(Debug, Clone)]
pub(crate) enum RowOutputKind {
    Variable(Variable),
}

#[derive(Debug, Default)]
pub(crate) struct RowOutput {
    output: OutputMap,
}

type OutputMap = Vec<(String, RowOutputKind)>;

impl RowOutput {
    pub fn push<K: Into<String>>(&mut self, key: K, value: RowOutputKind) {
        self.output.push((key.into(), value))
    }

    pub async fn to_json(&self) -> Variable {
        let object = Variable::empty_object();

        for (key, kind) in &self.output {
            match kind {
                RowOutputKind::Variable(variable) => {
                    object.dot_insert(key.as_str(), variable.clone());
                }
            }
        }

        object
    }
}