Struct QueryWrapper

Source
pub struct QueryWrapper<'a, T>{
    pub root_condition: ConditionNode<'a>,
    pub order_by: Vec<OrderBy<'a>>,
    pub group_by: Vec<Cow<'a, str>>,
    pub having: Option<Cow<'a, str>>,
    pub limit: Option<usize>,
    pub offset: Option<usize>,
    pub select_columns: Vec<Cow<'a, str>>,
    pub custom_sql: Option<Cow<'a, str>>,
    /* private fields */
}
Expand description

优化后的QueryWrapper结构体

Fields§

§root_condition: ConditionNode<'a>§order_by: Vec<OrderBy<'a>>§group_by: Vec<Cow<'a, str>>§having: Option<Cow<'a, str>>§limit: Option<usize>§offset: Option<usize>§select_columns: Vec<Cow<'a, str>>§custom_sql: Option<Cow<'a, str>>

Implementations§

Source§

impl<'a, T> QueryWrapper<'a, T>

Source

pub fn new() -> Self

创建一个新的QueryWrapper实例

Source

pub fn eq<F, V>(self, column: F, value: V) -> Self
where F: FnOnce() -> V, V: Into<Cow<'a, str>>,

等于条件

Source

pub fn ne<F, V>(self, column: F, value: V) -> Self
where F: FnOnce() -> V, V: Into<Cow<'a, str>>,

不等于条件

Source

pub fn gt<F, V>(self, column: F, value: V) -> Self
where F: FnOnce() -> V, V: Into<Cow<'a, str>>,

大于条件

Source

pub fn ge<F, V>(self, column: F, value: V) -> Self
where F: FnOnce() -> V, V: Into<Cow<'a, str>>,

大于等于条件

Source

pub fn lt<F, V>(self, column: F, value: V) -> Self
where F: FnOnce() -> V, V: Into<Cow<'a, str>>,

小于条件

Source

pub fn le<F, V>(self, column: F, value: V) -> Self
where F: FnOnce() -> V, V: Into<Cow<'a, str>>,

小于等于条件

Source

pub fn like<F, V>(self, column: F, value: V) -> Self
where F: FnOnce() -> V, V: Into<Cow<'a, str>>,

模糊匹配条件

Source

pub fn not_like<F, V>(self, column: F, value: V) -> Self
where F: FnOnce() -> V, V: Into<Cow<'a, str>>,

不匹配条件

Source

pub fn like_left<F, V>(self, column: F, value: V) -> Self
where F: FnOnce() -> V, V: Into<Cow<'a, str>>,

左模糊匹配条件

Source

pub fn like_right<F, V>(self, column: F, value: V) -> Self
where F: FnOnce() -> V, V: Into<Cow<'a, str>>,

右模糊匹配条件

Source

pub fn is_null<F, V>(self, column: F) -> Self
where F: FnOnce() -> V, V: Into<Cow<'a, str>>,

为空条件

Source

pub fn is_not_null<F, V>(self, column: F) -> Self
where F: FnOnce() -> V, V: Into<Cow<'a, str>>,

不为空条件

Source

pub fn in<F, V, I>(self, column: F, values: I) -> Self
where F: FnOnce() -> V, V: Into<Cow<'a, str>>, I: IntoIterator<Item = V>,

在列表中条件

Source

pub fn not_in<F, V, I>(self, column: F, values: I) -> Self
where F: FnOnce() -> V, V: Into<Cow<'a, str>>, I: IntoIterator<Item = V>,

不在列表中条件

Source

pub fn between<F, V>(self, column: F, value1: V, value2: V) -> Self
where F: FnOnce() -> V, V: Into<Cow<'a, str>>,

在范围内条件

Source

pub fn not_between<F, V>(self, column: F, value1: V, value2: V) -> Self
where F: FnOnce() -> V, V: Into<Cow<'a, str>>,

不在范围内条件

Source

pub fn or(self) -> Self

添加OR逻辑操作符

Source

pub fn nested<F>(self, f: F) -> Self
where F: FnOnce(QueryWrapper<'a, T>) -> QueryWrapper<'a, T>,

添加嵌套条件

Source

pub fn apply<V: Into<Cow<'a, str>>>(self, sql: V) -> Self

添加自定义SQL

Source

pub fn order_by<F, V>(self, column: F, direction: OrderDirection) -> Self
where F: FnOnce() -> V, V: Into<Cow<'a, str>>,

设置排序条件

Source

pub fn order_by_asc<F, V>(self, column: F) -> Self
where F: FnOnce() -> V, V: Into<Cow<'a, str>>,

设置升序排序

Source

pub fn order_by_desc<F, V>(self, column: F) -> Self
where F: FnOnce() -> V, V: Into<Cow<'a, str>>,

设置降序排序

Source

pub fn group_by<V, I>(self, columns: I) -> Self
where V: Into<Cow<'a, str>>, I: IntoIterator<Item = V>,

设置分组条件

Source

pub fn having<V: Into<Cow<'a, str>>>(self, condition: V) -> Self

设置HAVING条件

Source

pub fn select<V, I>(self, columns: I) -> Self
where V: Into<Cow<'a, str>>, I: IntoIterator<Item = V>,

设置查询列

Source

pub fn limit(self, limit: usize) -> Self

设置分页

Source

pub fn offset(self, offset: usize) -> Self

设置偏移量

Source

pub fn build_where_clause(&self) -> String

生成WHERE子句

Source

pub fn build_order_by_clause(&self) -> String

生成ORDER BY子句

Source

pub fn build_group_by_clause(&self) -> String

生成GROUP BY子句

Source

pub fn build_having_clause(&self) -> String

生成HAVING子句

Source

pub fn build_limit_offset_clause(&self) -> String

生成LIMIT和OFFSET子句

Source

pub fn build_select_clause(&self) -> String

生成SELECT子句

Trait Implementations§

Source§

impl<'a, T> Clone for QueryWrapper<'a, T>

Source§

fn clone(&self) -> QueryWrapper<'a, T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<'a, T> Debug for QueryWrapper<'a, T>

Source§

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

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

impl<'a, T> Default for QueryWrapper<'a, T>

Source§

fn default() -> QueryWrapper<'a, T>

Returns the “default value” for a type. Read more
Source§

impl<'a, T> Wrapper<T> for QueryWrapper<'_, T>

Auto Trait Implementations§

§

impl<'a, T> Freeze for QueryWrapper<'a, T>

§

impl<'a, T> RefUnwindSafe for QueryWrapper<'a, T>
where T: RefUnwindSafe,

§

impl<'a, T> Send for QueryWrapper<'a, T>
where T: Send,

§

impl<'a, T> Sync for QueryWrapper<'a, T>
where T: Sync,

§

impl<'a, T> Unpin for QueryWrapper<'a, T>
where T: Unpin,

§

impl<'a, T> UnwindSafe for QueryWrapper<'a, T>
where T: UnwindSafe,

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
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> 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.