rbatis_codegen/codegen/syntax_tree_pysql/choose_node.rs
1use crate::codegen::syntax_tree_pysql::{Name, NodeType};
2
3/// Represents a `choose` node in py_sql.
4/// It provides a way to conditionally execute different blocks of SQL, similar to a switch statement.
5/// It must contain one or more `when` child nodes and can optionally have an `otherwise` child node.
6///
7/// # Example
8///
9/// PySQL syntax:
10/// ```py
11/// choose:
12/// when test="type == 'A'":
13/// sql_block_A
14/// when test="type == 'B'":
15/// sql_block_B
16/// otherwise:
17/// sql_block_default
18/// ```
19#[derive(Clone, Debug, Eq, PartialEq)]
20pub struct ChooseNode {
21 pub when_nodes: Vec<NodeType>,
22 pub otherwise_node: Option<Box<NodeType>>,
23}
24
25impl Name for ChooseNode {
26 fn name() -> &'static str {
27 "choose"
28 }
29}