good_ormning/sqlite/query/
select.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
use {
    super::{
        expr::{
            ExprType,
        },
        select_body::{
            build_select_junction,
            SelectBody,
            SelectJunction,
        },
        utils::{
            build_with,
            QueryBody,
            With,
        },
    },
    crate::{
        sqlite::{
            QueryResCount,
        },
        utils::Tokens,
    },
    std::collections::HashMap,
};

#[derive(Clone, Debug)]
pub struct Select {
    pub with: Option<With>,
    pub body: SelectBody,
    pub body_junctions: Vec<SelectJunction>,
}

impl QueryBody for Select {
    fn build(
        &self,
        ctx: &mut super::utils::SqliteQueryCtx,
        path: &rpds::Vector<String>,
        res_count: QueryResCount,
    ) -> (ExprType, Tokens) {
        let mut out = Tokens::new();
        if let Some(w) = &self.with {
            out.s(&build_with(ctx, path, w).to_string());
        }
        let body: (ExprType, Tokens) = self.body.build(ctx, &HashMap::new(), path, res_count);
        out.s(&body.1.to_string());
        out.s(&build_select_junction(ctx, path, &body.0, &self.body_junctions).to_string());
        return (body.0, out);
    }
}