yang_base/table/table_query/
build.rs1use super::TableQuery;
5use crate::table::{QueryParams, 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 }
39 }
40
41 #[cfg(not(feature = "mysql"))]
45 pub(crate) fn new(
46 table_config: Arc<TableConfig>,
47 user_roles: Arc<[String]>,
48 _pool: Option<()>,
49 ) -> Self {
50 let user_roles_set: HashSet<String> = user_roles.iter().cloned().collect();
51 Self {
52 table_config,
53 user_roles,
54 user_roles_set,
55 query_params: QueryParams::new(),
56 include_trashed: false,
57 tenant_scope: None,
58 slow_threshold: None,
59 request_id: None,
60 }
61 }
62
63 pub fn with_slow_threshold(mut self, threshold: Option<std::time::Duration>) -> Self {
68 self.slow_threshold = threshold;
69 self
70 }
71
72 pub fn with_request_id(mut self, request_id: crate::action::RequestId) -> Self {
74 self.request_id = Some(request_id);
75 self
76 }
77
78 #[cfg(all(test, feature = "mysql"))]
82 pub(crate) fn new_without_pool(table_config: Arc<TableConfig>) -> Self {
83 Self::new(table_config, Arc::from(vec![]), None)
84 }
85}