rbatis_codegen/codegen/syntax_tree_pysql/
otherwise_node.rs

1use crate::codegen::syntax_tree_pysql::{DefaultName, Name, NodeType, ToHtml};
2
3/// Represents an `otherwise` node in py_sql.
4/// It's used within a `choose` block to provide a default SQL block to execute if none of the `when` conditions are met.
5/// It can also be represented by `_`.
6///
7/// # Example
8///
9/// PySQL syntax (inside a `choose` block):
10/// ```py
11/// choose:
12///   when test="type == 'A'":
13///     sql_block_A
14///   otherwise:  // or _:
15///     sql_block_default
16/// ```
17#[derive(Clone, Debug, Eq, PartialEq)]
18pub struct OtherwiseNode {
19    pub childs: Vec<NodeType>,
20}
21
22impl Name for OtherwiseNode {
23    fn name() -> &'static str {
24        "otherwise"
25    }
26}
27
28impl DefaultName for OtherwiseNode {
29    fn default_name() -> &'static str {
30        "_"
31    }
32}
33
34impl ToHtml for OtherwiseNode {
35    fn as_html(&self) -> String {
36        let mut childs = String::new();
37        for x in &self.childs {
38            childs.push_str(&x.as_html());
39        }
40        format!("<otherwise>{}</otherwise>", childs)
41    }
42}