pub fn search(
        &self,
        city_id: Option<ID>,
        district_id: Option<ID>,
        village_name: Option<&str>,
        come_from: Option<&str>,
        age: Option<i32>,
        residence_address: Option<&str>,
        gender: Option<&str>,
        status: Option<SubReportStatus>,
        query: &str,
        creator_id: Option<i64>,
        offset: i64,
        limit: i64,
    ) -> Result<EntriesResult<SubReport>> {
        use crate::schema::sub_reports::{self, dsl};
        let mut filterer: Box<dyn BoxableExpression<sub_reports::table, _, SqlType = sql_types::Bool>> =
            Box::new(dsl::id.ne(0));

        if let Some(city_id) = city_id {
            filterer = Box::new(filterer.and(dsl::city_id.eq(city_id)));
        }

        let query = query.trim();

        if query != "" {
            let like_clause = format!("%{}%", query).to_lowercase();
            filterer = Box::new(filterer.and(lower(dsl::full_name).like(like_clause)));
        }

        if let Some(village_name) = village_name {
            filterer = Box::new(filterer.and(dsl::meta.contains(vec![format!("village={}", village_name)])));
        }

        if let Some(district_id) = district_id {
            filterer = Box::new(filterer.and(dsl::district_id.eq(district_id)));
        }

        if let Some(creator_id) = creator_id {
            filterer = Box::new(filterer.and(dsl::creator_id.eq(creator_id)));
        }

        if let Some(age) = age {
            filterer = Box::new(filterer.and(dsl::age.eq(age as i32)));
        }

        if let Some(status) = status {
            dbg!(status);
            filterer = Box::new(filterer.and(dsl::status.eq(status as i32)));
        }

        if let Some(residence_address) = residence_address {
            filterer =
                Box::new(filterer.and(lower(dsl::residence_address).eq(residence_address.to_lowercase())));
        }

        if let Some(come_from) = come_from {
            filterer = Box::new(filterer.and(lower(dsl::coming_from).eq(come_from.to_lowercase())));
        }
        if let Some(gender) = gender {
            filterer = Box::new(filterer.and(dsl::gender.eq(gender)));
        }

        // debug!("query {:?}", diesel::debug_query::<diesel::pg::Pg, _>(&dsl::sub_reports
        //     .filter(&filterer)
        //     .offset(offset)
        //     .limit(limit)
        //     .order(dsl::ts.desc())));

        Ok(EntriesResult::new(
            dsl::sub_reports
                .filter(&filterer)
                .offset(offset)
                .limit(limit)
                .order(dsl::ts.desc())
                .load::<SubReport>(self.db)?,
            dsl::sub_reports
                .filter(filterer)
                .select(diesel::dsl::count(dsl::id))
                .first(self.db)?,
        ))
    }
/// Search for specific sub report by creator
Search for specific sub report by creator
Search for specific sub report by creator
pub fn search(
        &self,
        city_id: Option<ID>,
        district_id: Option<ID>,
        village_name: Option<&str>,
        come_from: Option<&str>,
        age: Option<i32>,
        residence_address: Option<&str>,
        gender: Option<&str>,
        status: Option<SubReportStatus>,
        query: &str,
        creator_id: Option<i64>,
        offset: i64,
        limit: i64,
    ) -> Result<EntriesResult<SubReport>> {
        use crate::schema::sub_reports::{self, dsl};
        let mut filterer: Box<dyn BoxableExpression<sub_reports::table, _, SqlType = sql_types::Bool>> =
            Box::new(dsl::id.ne(0));
        if let Some(city_id) = city_id {
            filterer = Box::new(filterer.and(dsl::city_id.eq(city_id)));
        }
        let query = query.trim();
        if query != "" {
            let like_clause = format!("%{}%", query).to_lowercase();
            filterer = Box::new(filterer.and(lower(dsl::full_name).like(like_clause)));
        }
        if let Some(village_name) = village_name {
            filterer = Box::new(filterer.and(dsl::meta.contains(vec![format!("village={}", village_name)])));
        }
        if let Some(district_id) = district_id {
            filterer = Box::new(filterer.and(dsl::district_id.eq(district_id)));
        }
        if let Some(creator_id) = creator_id {
            filterer = Box::new(filterer.and(dsl::creator_id.eq(creator_id)));
        }
        if let Some(age) = age {
            filterer = Box::new(filterer.and(dsl::age.eq(age as i32)));
        }
        if let Some(status) = status {
            dbg!(status);
            filterer = Box::new(filterer.and(dsl::status.eq(status as i32)));
        }
        if let Some(residence_address) = residence_address {
            filterer =
                Box::new(filterer.and(lower(dsl::residence_address).eq(residence_address.to_lowercase())));
        }
        if let Some(come_from) = come_from {
            filterer = Box::new(filterer.and(lower(dsl::coming_from).eq(come_from.to_lowercase())));
        }
        if let Some(gender) = gender {
            filterer = Box::new(filterer.and(dsl::gender.eq(gender)));
        }
        // debug!("query {:?}", diesel::debug_query::<diesel::pg::Pg, _>(&dsl::sub_reports
        //     .filter(&filterer)
        //     .offset(offset)
        //     .limit(limit)
        //     .order(dsl::ts.desc())));
        Ok(EntriesResult::new(
            dsl::sub_reports
                .filter(&filterer)
                .offset(offset)
                .limit(limit)
                .order(dsl::ts.desc())
                .load::<SubReport>(self.db)?,
            dsl::sub_reports
                .filter(filterer)
                .select(diesel::dsl::count(dsl::id))
                .first(self.db)?,
        ))
    }
pub fn search ( & self , city_id : Option < ID > , district_id : Option < ID > , village_name : Option < & str > , come_from : Option < & str > , age : Option < i32 > , residence_address : Option < & str > , gender : Option < & str > , status : Option < SubReportStatus > , query : & str , creator_id : Option < i64 > , offset : i64 , limit : i64 , ) -> Result < EntriesResult < SubReport > > { use crate :: schema :: sub_reports :: { self , dsl } ; let mut filterer : Box < dyn BoxableExpression < sub_reports :: table , _ , SqlType = sql_types :: Bool > > = Box :: new ( dsl :: id . ne ( 0 ) ) ; if let Some ( city_id ) = city_id { filterer = Box :: new ( filterer . and ( dsl :: city_id . eq ( city_id ) ) ) ; } let query = query . trim ( ) ; if query != " " { let like_clause = format ! ( " " query ) . to_lowercase ( ) ; filterer = Box :: new ( filterer . and ( lower ( dsl :: full_name ) . like ( like_clause ) ) ) ; } if let Some ( village_name ) = village_name { filterer = Box :: new ( filterer . and ( dsl :: meta . contains ( vec ! [ format ( " " village_name ) ] ) ) ) ; } if let Some ( district_id ) = district_id { filterer = Box :: new ( filterer . and ( dsl :: district_id . eq ( district_id ) ) ) ; } if let Some ( creator_id ) = creator_id { filterer = Box :: new ( filterer . and ( dsl :: creator_id . eq ( creator_id ) ) ) ; } if let Some ( age ) = age { filterer = Box :: new ( filterer . and ( dsl :: age . eq ( age as i32 ) ) ) ; } if let Some ( status ) = status { dbg ! ( status ) ; filterer = Box :: new ( filterer . and ( dsl :: status . eq ( status as i32 ) ) ) ; } if let Some ( residence_address ) = residence_address { filterer = Box :: new ( filterer . and ( lower ( dsl :: residence_address ) . eq ( residence_address . to_lowercase ( ) ) ) ) ; } if let Some ( come_from ) = come_from { filterer = Box :: new ( filterer . and ( lower ( dsl :: coming_from ) . eq ( come_from . to_lowercase ( ) ) ) ) ; } if let Some ( gender ) = gender { filterer = Box :: new ( filterer . and ( dsl :: gender . eq ( gender ) ) ) ; } // debug!("query {:?}", diesel::debug_query::<diesel::pg::Pg, _>(&dsl::sub_reports //     .filter(&filterer) //     .offset(offset) //     .limit(limit) //     .order(dsl::ts.desc()))); Ok ( EntriesResult :: new ( dsl :: sub_reports . filter ( & filterer ) . offset ( offset ) . limit ( limit ) . order ( dsl :: ts . desc ( ) ) . load :: < SubReport > ( self . db ) ? , dsl :: sub_reports . filter ( filterer ) . select ( diesel :: dsl :: count ( dsl :: id ) ) . first ( self . db ) ? , ) ) }
Search for specific sub report by creator
Search for specific sub report by creator
&self
city_id
Option<ID>
district_id
Option<ID>
village_name
Option<&str>
come_from
Option<&str>
age
Option<i32>
residence_address
Option<&str>
gender
Option<&str>
status
Option<SubReportStatus>
query
&str
creator_id
Option<i64>
offset
i64
limit
i64
&self
city_id
Option<ID>
district_id
Option<ID>
village_name
Option<&str>
come_from
Option<&str>
age
Option<i32>
residence_address
Option<&str>
gender
Option<&str>
status
Option<SubReportStatus>
query
&str
creator_id
Option<i64>
offset
i64
limit
i64