Trait WhereAttributeMacro

Source
pub trait WhereAttributeMacro {
    // Required methods
    fn generate_where_clause(&self) -> Vec<String>;
    fn generate_where_clause_with_index(&self, index: usize) -> Vec<String>;
}
Expand description

WhereAttributeMacro trait 定义了处理字段属性宏的功能。

这个 trait 主要用于解析和处理 #[where(...)] 属性宏,该宏用于 定制 SQL 语句中的字段部分。通过实现这个 trait,可以根据结构体 字段上的 #[where] 宏指定的参数生成对应的字段列表。

Required Methods§

Source

fn generate_where_clause(&self) -> Vec<String>

解析 #[where(...)] 属性宏,并生成字段列表。

此方法会分析结构体字段上的 #[where] 宏参数,如 ignore, rename, index, conditioncondition_all 并据此生成对应的字段名称列表。这个列表通常用于构建 SQL 语句的 WHERE 部分。

返回值是一个包含字段名称的 String 向量。 数据库选择为 Postgres 数据应返回为 [“field1 [condition] $1”, “[condition_all]”, “[rename] [condition] $3”, “field4 [condtion] $[index]”] 数据库选择为 MySql 数据应返回为 [“field1 [condition] ?”, “[condition_all]”, “[rename] [condition] ?”, “field4 [condtion] ?”]

Source

fn generate_where_clause_with_index(&self, index: usize) -> Vec<String>

Implementors§