yang_base/table/table_query/
build.rs1use super::TableQuery;
5use crate::table::{QueryParams, RegexCache, TableConfig};
6use std::collections::HashSet;
7use std::sync::Arc;
8
9impl TableQuery {
10 #[cfg(feature = "mysql")]
22 pub(crate) fn new(
23 table_config: Arc<TableConfig>,
24 user_roles: Arc<[String]>,
25 pool: Option<Arc<sqlx::MySqlPool>>,
26 ) -> Self {
27 let user_roles_set: HashSet<String> = user_roles.iter().cloned().collect();
28 Self {
29 table_config,
30 user_roles,
31 user_roles_set,
32 query_params: QueryParams::new(),
33 include_trashed: false,
34 tenant_scope: None,
35 pool,
36 slow_threshold: None,
37 request_id: None,
38 regex_cache: RegexCache::default(),
39 }
40 }
41
42 #[cfg(not(feature = "mysql"))]
46 pub(crate) fn new(
47 table_config: Arc<TableConfig>,
48 user_roles: Arc<[String]>,
49 _pool: Option<()>,
50 ) -> Self {
51 let user_roles_set: HashSet<String> = user_roles.iter().cloned().collect();
52 Self {
53 table_config,
54 user_roles,
55 user_roles_set,
56 query_params: QueryParams::new(),
57 include_trashed: false,
58 tenant_scope: None,
59 slow_threshold: None,
60 request_id: None,
61 regex_cache: RegexCache::default(),
62 }
63 }
64
65 pub fn with_slow_threshold(mut self, threshold: Option<std::time::Duration>) -> Self {
70 self.slow_threshold = threshold;
71 self
72 }
73
74 pub fn with_request_id(mut self, request_id: crate::action::RequestId) -> Self {
76 self.request_id = Some(request_id);
77 self
78 }
79
80 pub fn with_regex_cache(mut self, cache: RegexCache) -> Self {
83 self.regex_cache = cache;
84 self
85 }
86
87 #[cfg(all(test, feature = "mysql"))]
91 pub(crate) fn new_without_pool(table_config: Arc<TableConfig>) -> Self {
92 Self::new(table_config, Arc::from(vec![]), None)
93 }
94}