pub struct QuerySearch {
pub q: Option<String>,
pub sort: Option<String>,
pub offset: i64,
pub page_size: i64,
pub include_total: Option<bool>,
}Expand description
Struct used to deserialize with serde query strings
from a request URL.
§Examples
Valid URLs could be:
/api/users?q=marian&include_total=true/api/v1/sales?q=customer:john&page_size=100/some-endpoint?page_size=20&sort=-name
When an instance is created through serde,
the page_size attribute is set to 50
if the stream serialized does not have the
value set.
Fields§
§q: Option<String>§sort: Option<String>§offset: i64§page_size: i64§include_total: Option<bool>Implementations§
Source§impl QuerySearch
impl QuerySearch
Sourcepub fn parse_sort(&self, allowed_fields: &[&str]) -> Vec<String>
pub fn parse_sort(&self, allowed_fields: &[&str]) -> Vec<String>
Parse sort argument “col1,col2,-col3…” into a vector of strings, and if the column name starts with “-”, it’s translated to a DESC keyword, e.g. “-name” –> “name DESC”.
use actix_contrib_rest::query::QuerySearch;
let q = QuerySearch { q: None, offset: 0, page_size: 10, sort: None, include_total: None };
assert_eq!(q.parse_sort(&["a", "b"]), Vec::<String>::new());
let q = QuerySearch { q: None, offset: 0, page_size: 10, sort: Some(String::from("a,-b")), include_total: None };
assert_eq!(q.parse_sort(&["a", "b"]), &[String::from("a"), String::from("b DESC")]);
let q = QuerySearch { q: None, offset: 0, page_size: 10, sort: Some(String::from("name,-b,c")), include_total: None };
assert_eq!(q.parse_sort(&vec!["name", "c"]), &[String::from("name"), String::from("c")]);Sourcepub fn sort_as_order_by_args(
&self,
allowed_fields: &[&str],
default: &str,
) -> String
pub fn sort_as_order_by_args( &self, allowed_fields: &[&str], default: &str, ) -> String
Parse sort argument “col1,col2,-col3…” into a compatible SQL ORDER BY expression,
e.g. name,-age –> name, age DESC, to be concatenated in a SQL SELECT query.
use actix_contrib_rest::query::QuerySearch;
let q = QuerySearch { q: None, offset: 0, page_size: 10, sort: None, include_total: None };
assert_eq!(q.sort_as_order_by_args(&["a", "b"], "a"), "a");
let q = QuerySearch { q: None, offset: 0, page_size: 10, sort: Some(String::from("a,-b")), include_total: None };
assert_eq!(q.sort_as_order_by_args(&["a", "b"], "a"), "a, b DESC");
let q = QuerySearch { q: None, offset: 0, page_size: 10, sort: Some(String::from("name,-b,c")), include_total: None };
assert_eq!(q.sort_as_order_by_args(&["a", "h"], "c"), "c");Trait Implementations§
Source§impl Clone for QuerySearch
impl Clone for QuerySearch
Source§fn clone(&self) -> QuerySearch
fn clone(&self) -> QuerySearch
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for QuerySearch
impl Debug for QuerySearch
Source§impl<'de> Deserialize<'de> for QuerySearch
impl<'de> Deserialize<'de> for QuerySearch
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
impl Eq for QuerySearch
Source§impl PartialEq for QuerySearch
impl PartialEq for QuerySearch
Source§fn eq(&self, other: &QuerySearch) -> bool
fn eq(&self, other: &QuerySearch) -> bool
Tests for
self and other values to be equal, and is used by ==.impl StructuralPartialEq for QuerySearch
Source§impl Validate for QuerySearch
impl Validate for QuerySearch
Source§impl<'v_a> ValidateArgs<'v_a> for QuerySearch
impl<'v_a> ValidateArgs<'v_a> for QuerySearch
Auto Trait Implementations§
impl Freeze for QuerySearch
impl RefUnwindSafe for QuerySearch
impl Send for QuerySearch
impl Sync for QuerySearch
impl Unpin for QuerySearch
impl UnsafeUnpin for QuerySearch
impl UnwindSafe for QuerySearch
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<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.