Skip to main content

sqlx_data_params/
search.rs

1use crate::{IntoParams, Params};
2
3#[derive(Clone, Debug, PartialEq)]
4pub struct SearchParams {
5    pub query: String,
6    pub fields: Vec<String>,
7
8    pub case_sensitive: bool,
9
10    pub exact_match: bool,
11}
12
13impl SearchParams {
14    pub fn new(query: impl Into<String>, fields: impl IntoIterator<Item = String>) -> Self {
15        Self {
16            query: query.into(),
17            fields: fields.into_iter().collect(),
18            case_sensitive: false,
19            exact_match: false,
20        }
21    }
22
23    pub fn with_case_sensitive(mut self, sensitive: bool) -> Self {
24        self.case_sensitive = sensitive;
25        self
26    }
27
28    pub fn with_exact_match(mut self, exact: bool) -> Self {
29        self.exact_match = exact;
30        self
31    }
32}
33
34impl IntoParams for SearchParams {
35    fn into_params(self) -> Params {
36        Params {
37            filters: None,
38            search: Some(self),
39            sort_by: None,
40            pagination: None,
41            limit: None,
42            offset: None,
43        }
44    }
45}