pub struct QueryParams {
pub fields: Option<Vec<String>>,
pub where_conditions: Vec<WhereCondition>,
pub order_by: Vec<(String, SortOrder)>,
pub page: Option<usize>,
pub page_size: Option<usize>,
}Expand description
查询参数结构体
包含完整的查询参数,包括字段选择、WHERE 条件、排序规则和分页参数。
§字段
fields:字段选择列表,None 表示选择所有字段where_conditions:WHERE 条件列表order_by:排序规则列表,元组格式为 (字段名, 排序方向)page:当前页码,从 1 开始page_size:每页大小
§示例
use yang_base::table::{QueryParams, WhereCondition, SortOrder};
use serde_json::json;
let mut params = QueryParams::new();
// 选择特定字段
params.fields = Some(vec!["id".to_string(), "name".to_string(), "email".to_string()]);
// 添加 WHERE 条件
params.where_conditions.push(WhereCondition::Eq {
field: "status".to_string(),
value: json!("active"),
});
params.where_conditions.push(WhereCondition::Gt {
field: "age".to_string(),
value: json!(18),
});
// 添加排序规则
params.order_by.push(("created_at".to_string(), SortOrder::Desc));
params.order_by.push(("name".to_string(), SortOrder::Asc));
// 设置分页参数
params.page = Some(1);
params.page_size = Some(20);Fields§
§fields: Option<Vec<String>>字段选择列表
None:选择所有字段Some(vec):选择指定字段
where_conditions: Vec<WhereCondition>WHERE 条件列表
多个条件之间使用 AND 连接
order_by: Vec<(String, SortOrder)>排序规则列表
元组格式为 (字段名, 排序方向)
page: Option<usize>当前页码
从 1 开始,None 表示不分页
page_size: Option<usize>每页大小
None 表示使用默认值或不分页
Implementations§
Source§impl QueryParams
impl QueryParams
Sourcepub fn with_fields(self, fields: Vec<String>) -> Self
pub fn with_fields(self, fields: Vec<String>) -> Self
Sourcepub fn with_condition(self, condition: WhereCondition) -> Self
pub fn with_condition(self, condition: WhereCondition) -> Self
添加 WHERE 条件
§参数
condition:WHERE 条件
§返回值
返回 self 以支持链式调用
§示例
use yang_base::table::{QueryParams, WhereCondition};
use serde_json::json;
let params = QueryParams::new()
.with_condition(WhereCondition::Eq {
field: "status".to_string(),
value: json!("active"),
});
assert_eq!(params.where_conditions.len(), 1);Sourcepub fn with_order_by(self, field: String, order: SortOrder) -> Self
pub fn with_order_by(self, field: String, order: SortOrder) -> Self
Sourcepub fn with_pagination(self, page: usize, page_size: usize) -> Self
pub fn with_pagination(self, page: usize, page_size: usize) -> Self
Trait Implementations§
Source§impl Clone for QueryParams
impl Clone for QueryParams
Source§impl Debug for QueryParams
impl Debug for QueryParams
Source§impl Default for QueryParams
impl Default for QueryParams
Source§impl<'de> Deserialize<'de> for QueryParams
impl<'de> Deserialize<'de> for QueryParams
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
Auto Trait Implementations§
impl Forget for QueryParams
impl Freeze for QueryParams
impl Move for QueryParams
impl RefUnwindSafe for QueryParams
impl Send for QueryParams
impl Sync for QueryParams
impl Unpin for QueryParams
impl UnsafeUnpin for QueryParams
impl UnwindSafe for QueryParams
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