#[non_exhaustive]pub enum WhereCondition {
Show 14 variants
Eq {
field: String,
value: Value,
},
In {
field: String,
values: Vec<Value>,
},
Like {
field: String,
pattern: String,
},
Gt {
field: String,
value: Value,
},
Gte {
field: String,
value: Value,
},
Lt {
field: String,
value: Value,
},
Lte {
field: String,
value: Value,
},
IsNull {
field: String,
},
IsNotNull {
field: String,
},
Ne {
field: String,
value: Value,
},
Between {
field: String,
lo: Value,
hi: Value,
},
NotIn {
field: String,
values: Vec<Value>,
},
And {
conditions: Vec<WhereCondition>,
},
Or {
conditions: Vec<WhereCondition>,
},
}Expand description
WHERE 条件枚举
定义各种查询条件类型,支持常见的 SQL WHERE 子句操作。
§变体
Eq:等于条件 (field = value)In:包含于列表条件 (field IN (values))Like:模糊匹配条件 (field LIKE pattern)Gt:大于条件 (field > value)Gte:大于等于条件 (field >= value)Lt:小于条件 (field < value)Lte:小于等于条件 (field <= value)IsNull:空值判断 (field IS NULL)IsNotNull:非空值判断 (field IS NOT NULL)
§示例
use yang_base::table::WhereCondition;
use serde_json::json;
// 等于条件
let eq_condition = WhereCondition::Eq {
field: "status".to_string(),
value: json!("active"),
};
// 包含条件
let in_condition = WhereCondition::In {
field: "role".to_string(),
values: vec![json!("admin"), json!("user")],
};
// 模糊匹配
let like_condition = WhereCondition::Like {
field: "name".to_string(),
pattern: "%alice%".to_string(),
};
// 大于条件
let gt_condition = WhereCondition::Gt {
field: "age".to_string(),
value: json!(18),
};
// 空值判断
let is_null_condition = WhereCondition::IsNull {
field: "deleted_at".to_string(),
};Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
Eq
In
Like
Gt
Gte
Lt
Lte
IsNull
IsNotNull
Ne
Between
NotIn
And
逻辑与组(嵌套子条件全部成立),SQL 渲染为 (c1 AND c2 AND ...)
空组等价于恒真(1=1),与顶层「无条件」语义一致。
§字段
conditions:子条件列表,递归可含And/Or组
Fields
§
conditions: Vec<WhereCondition>子条件列表
Or
逻辑或组(嵌套子条件任一成立),SQL 渲染为 (c1 OR c2 OR ...)
空组等价于恒假(1=0),避免拼出非法的空括号。
§字段
conditions:子条件列表,递归可含And/Or组
Fields
§
conditions: Vec<WhereCondition>子条件列表
Implementations§
Trait Implementations§
Source§impl Clone for WhereCondition
impl Clone for WhereCondition
Source§impl Debug for WhereCondition
impl Debug for WhereCondition
Source§impl<'de> Deserialize<'de> for WhereCondition
impl<'de> Deserialize<'de> for WhereCondition
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl JsonSchema for WhereCondition
impl JsonSchema for WhereCondition
Source§fn schema_name() -> String
fn schema_name() -> String
The name of the generated JSON Schema. Read more
Source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
Returns a string that uniquely identifies the schema produced by this type. Read more
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Generates a JSON Schema for this type. Read more
Source§fn is_referenceable() -> bool
fn is_referenceable() -> bool
Whether JSON Schemas generated for this type should be re-used where possible using the
$ref keyword. Read moreSource§impl PartialEq for WhereCondition
impl PartialEq for WhereCondition
Source§impl Serialize for WhereCondition
impl Serialize for WhereCondition
impl StructuralPartialEq for WhereCondition
Auto Trait Implementations§
impl Forget for WhereCondition
impl Freeze for WhereCondition
impl Move for WhereCondition
impl RefUnwindSafe for WhereCondition
impl Send for WhereCondition
impl Sync for WhereCondition
impl Unpin for WhereCondition
impl UnsafeUnpin for WhereCondition
impl UnwindSafe for WhereCondition
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more