From abb986001757af25f462c469365a068f2b879808 Mon Sep 17 00:00:00 2001 From: photino Date: Wed, 9 Aug 2023 13:19:04 +0800 Subject: [PATCH] Update QueryBuilder and MutationBuilder --- zino-core/src/model/mutation.rs | 2 +- zino-core/src/model/query.rs | 36 ++++++++++++++++----------------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/zino-core/src/model/mutation.rs b/zino-core/src/model/mutation.rs index fc3e0a59..53628922 100644 --- a/zino-core/src/model/mutation.rs +++ b/zino-core/src/model/mutation.rs @@ -114,7 +114,7 @@ impl MutationBuilder { /// Sets the value of the field. #[inline] - pub fn set(&mut self, field: S, value: T) -> &mut Self + pub fn set(mut self, field: S, value: T) -> Self where S: Into, T: Into, diff --git a/zino-core/src/model/query.rs b/zino-core/src/model/query.rs index b325d269..060127b8 100644 --- a/zino-core/src/model/query.rs +++ b/zino-core/src/model/query.rs @@ -296,7 +296,7 @@ impl QueryBuilder { /// Adds a field to the projection. #[inline] - pub fn field>(&mut self, field: S) -> &mut Self { + pub fn field>(mut self, field: S) -> Self { let field = field.into(); if !self.fields.contains(&field) { self.fields.push(field); @@ -306,7 +306,7 @@ impl QueryBuilder { /// Adds a filter with the condition for equal parts. #[inline] - pub fn and_eq(&mut self, field: S, value: T) -> &mut Self + pub fn and_eq(mut self, field: S, value: T) -> Self where S: Into, T: Into, @@ -317,7 +317,7 @@ impl QueryBuilder { /// Adds a filter with the condition for non-equal parts. #[inline] - pub fn and_ne(&mut self, field: S, value: T) -> &mut Self + pub fn and_ne(mut self, field: S, value: T) -> Self where S: Into, T: Into, @@ -329,7 +329,7 @@ impl QueryBuilder { /// Adds a filter with the condition for a field less than the value. #[inline] - pub fn and_lt(&mut self, field: S, value: T) -> &mut Self + pub fn and_lt(mut self, field: S, value: T) -> Self where S: Into, T: Into, @@ -341,7 +341,7 @@ impl QueryBuilder { /// Adds a filter with the condition for a field not greater than the value. #[inline] - pub fn and_le(&mut self, field: S, value: T) -> &mut Self + pub fn and_le(mut self, field: S, value: T) -> Self where S: Into, T: Into, @@ -353,7 +353,7 @@ impl QueryBuilder { /// Adds a filter with the condition for a field greater than the value. #[inline] - pub fn and_gt(&mut self, field: S, value: T) -> &mut Self + pub fn and_gt(mut self, field: S, value: T) -> Self where S: Into, T: Into, @@ -365,7 +365,7 @@ impl QueryBuilder { /// Adds a filter with the condition for a field not less than the value. #[inline] - pub fn and_ge(&mut self, field: S, value: T) -> &mut Self + pub fn and_ge(mut self, field: S, value: T) -> Self where S: Into, T: Into, @@ -377,7 +377,7 @@ impl QueryBuilder { /// Adds a filter with the condition for a field whose value is in the list. #[inline] - pub fn and_in(&mut self, field: S, list: &[T]) -> &mut Self + pub fn and_in(mut self, field: S, list: &[T]) -> Self where S: Into, T: Into + Clone, @@ -389,7 +389,7 @@ impl QueryBuilder { /// Adds a filter with the condition for a field whose value is not in the list. #[inline] - pub fn and_not_in(&mut self, field: S, list: &[T]) -> &mut Self + pub fn and_not_in(mut self, field: S, list: &[T]) -> Self where S: Into, T: Into + Clone, @@ -400,7 +400,7 @@ impl QueryBuilder { } /// Adds a filter with the condition for a field whose value is within a given range. - pub fn and_between(&mut self, field: S, min: T, max: T) -> &mut Self + pub fn and_between(mut self, field: S, min: T, max: T) -> Self where S: Into, T: Into, @@ -412,7 +412,7 @@ impl QueryBuilder { } /// Adds a filter with the condition to search for a specified pattern in a column. - pub fn and_like(&mut self, field: S, value: T) -> &mut Self + pub fn and_like(mut self, field: S, value: T) -> Self where S: Into, T: Into, @@ -424,49 +424,49 @@ impl QueryBuilder { /// Adds a filter which groups rows that have the same values into summary rows. #[inline] - pub fn group_by>(&mut self, fields: T) -> &mut Self { + pub fn group_by>(mut self, fields: T) -> Self { self.filters.upsert("$group", fields); self } /// Adds a filter which can be used with aggregate functions. #[inline] - pub fn having>(&mut self, selection: T) -> &mut Self { + pub fn having>(mut self, selection: T) -> Self { self.filters.upsert("$having", selection); self } /// Adds a sort with the specific order. #[inline] - pub fn order_by>(&mut self, field: S, descending: bool) -> &mut Self { + pub fn order_by>(mut self, field: S, descending: bool) -> Self { self.sort_order.push((field.into(), descending)); self } /// Adds a sort with the ascending order. #[inline] - pub fn order_asc>(&mut self, field: S) -> &mut Self { + pub fn order_asc>(mut self, field: S) -> Self { self.sort_order.push((field.into(), false)); self } /// Adds a sort with the descending order. #[inline] - pub fn order_desc>(&mut self, field: S) -> &mut Self { + pub fn order_desc>(mut self, field: S) -> Self { self.sort_order.push((field.into(), true)); self } /// Sets the offset. #[inline] - pub fn offset(&mut self, offset: usize) -> &mut Self { + pub fn offset(mut self, offset: usize) -> Self { self.offset = offset; self } /// Sets the limit. #[inline] - pub fn limit(&mut self, limit: usize) -> &mut Self { + pub fn limit(mut self, limit: usize) -> Self { self.limit = limit; self }