Skip to main content

WhereCondition

Enum WhereCondition 

Source
#[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

等于条件 (field = value)

§字段

  • field:字段名
  • value:比较值

Fields

§field: String

字段名

§value: Value

比较值

§

In

包含于列表条件 (field IN (values))

§字段

  • field:字段名
  • values:值列表

Fields

§field: String

字段名

§values: Vec<Value>

值列表

§

Like

模糊匹配条件 (field LIKE pattern)

§字段

  • field:字段名
  • pattern:匹配模式,支持 % 和 _ 通配符

Fields

§field: String

字段名

§pattern: String

匹配模式

§

Gt

大于条件 (field > value)

§字段

  • field:字段名
  • value:比较值

Fields

§field: String

字段名

§value: Value

比较值

§

Gte

大于等于条件 (field >= value)

§字段

  • field:字段名
  • value:比较值

Fields

§field: String

字段名

§value: Value

比较值

§

Lt

小于条件 (field < value)

§字段

  • field:字段名
  • value:比较值

Fields

§field: String

字段名

§value: Value

比较值

§

Lte

小于等于条件 (field <= value)

§字段

  • field:字段名
  • value:比较值

Fields

§field: String

字段名

§value: Value

比较值

§

IsNull

空值判断 (field IS NULL)

§字段

  • field:字段名

Fields

§field: String

字段名

§

IsNotNull

非空值判断 (field IS NOT NULL)

§字段

  • field:字段名

Fields

§field: String

字段名

§

Ne

不等于条件 (field <> value)

§字段

  • field:字段名
  • value:比较值

Fields

§field: String

字段名

§value: Value

比较值

§

Between

区间条件 (field BETWEEN lo AND hi)

§字段

  • field:字段名
  • lo:区间下界
  • hi:区间上界

Fields

§field: String

字段名

§lo: Value

区间下界

§hi: Value

区间上界

§

NotIn

不在列表条件 (field NOT IN (values))

§字段

  • field:字段名
  • values:值列表

Fields

§field: String

字段名

§values: Vec<Value>

值列表

§

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§

Source§

impl WhereCondition

Source

pub fn field(&self) -> Option<&str>

获取条件涉及的字段名

叶子条件返回 Some(字段名);逻辑组(And/Or)无单一字段,返回 None。

§返回值

叶子返回 Some(&str),组节点返回 None

§示例
use yang_base::table::WhereCondition;
use serde_json::json;

let condition = WhereCondition::Eq {
    field: "status".to_string(),
    value: json!("active"),
};

assert_eq!(condition.field(), Some("status"));

Trait Implementations§

Source§

impl Clone for WhereCondition

Source§

fn clone(&self) -> WhereCondition

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for WhereCondition

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for WhereCondition

Source§

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 PartialEq for WhereCondition

Source§

fn eq(&self, other: &WhereCondition) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for WhereCondition

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for WhereCondition

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more