rbatis_codegen/codegen/syntax_tree_pysql/
when_node.rs

1use crate::codegen::syntax_tree_pysql::{Name, NodeType};
2
3/// Represents a `when` node in py_sql.
4/// It's used as a child of a `choose` node to define a conditional block of SQL.
5/// The SQL block within `when` is executed if its `test` condition evaluates to true and no preceding `when` in the same `choose` was true.
6///
7/// # Attributes
8///
9/// - `test`: The boolean expression to evaluate.
10///
11/// # Example
12///
13/// PySQL syntax (inside a `choose` block):
14/// ```py
15/// choose:
16///   when test="type == 'A'":
17///     sql_for_type_A
18///   when test="type == 'B'":
19///     sql_for_type_B
20/// ```
21#[derive(Clone, Debug, Eq, PartialEq)]
22pub struct WhenNode {
23    pub childs: Vec<NodeType>,
24    pub test: String,
25}
26
27impl Name for WhenNode {
28    fn name() -> &'static str {
29        "when"
30    }
31}