rbatis-codegen 4.8.0

The Rust SQL Toolkit and ORM Library. An async, pure Rust SQL crate featuring compile-time Dynamic SQL gen system
Documentation
use crate::codegen::syntax_tree_pysql::{Name, NodeType, ToHtml};

/// Represents a `when` node in py_sql.
/// It's used as a child of a `choose` node to define a conditional block of SQL.
/// The SQL block within `when` is executed if its `test` condition evaluates to true and no preceding `when` in the same `choose` was true.
///
/// # Attributes
///
/// - `test`: The boolean expression to evaluate.
///
/// # Example
///
/// PySQL syntax (inside a `choose` block):
/// ```py
/// choose:
///   when test="type == 'A'":
///     sql_for_type_A
///   when test="type == 'B'":
///     sql_for_type_B
/// ```
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct WhenNode {
    pub childs: Vec<NodeType>,
    pub test: String,
}

impl Name for WhenNode {
    fn name() -> &'static str {
        "when"
    }
}

impl ToHtml for WhenNode {
    fn as_html(&self) -> String {
        let mut childs = String::new();
        for x in &self.childs {
            childs.push_str(&x.as_html());
        }
        format!("<when test=\"{}\">{}</when>", self.test, childs)
    }
}