surrealdb/api/opt/
config.rs1use crate::{dbs::Capabilities, iam::Level};
2use std::time::Duration;
3
4#[derive(Debug, Clone, Default)]
6pub struct Config {
7 pub(crate) strict: bool,
8 pub(crate) notifications: bool,
9 pub(crate) query_timeout: Option<Duration>,
10 pub(crate) transaction_timeout: Option<Duration>,
11 #[cfg(any(feature = "native-tls", feature = "rustls"))]
12 pub(crate) tls_config: Option<super::Tls>,
13 pub(crate) auth: Level,
16 pub(crate) username: String,
17 pub(crate) password: String,
18 pub(crate) tick_interval: Option<Duration>,
19 pub(crate) capabilities: Capabilities,
20}
21
22impl Config {
23 pub fn new() -> Self {
25 Default::default()
26 }
27
28 pub fn set_strict(mut self, strict: bool) -> Self {
30 self.strict = strict;
31 self
32 }
33
34 pub fn strict(mut self) -> Self {
36 self.strict = true;
37 self
38 }
39
40 #[deprecated(
42 since = "1.1.0",
43 note = "Moved to `Capabilities::with_live_query_notifications()`"
44 )]
45 pub fn set_notifications(mut self, notifications: bool) -> Self {
46 self.notifications = notifications;
47 self
48 }
49
50 #[deprecated(
52 since = "1.1.0",
53 note = "Moved to `Capabilities::with_live_query_notifications()`"
54 )]
55 pub fn notifications(mut self) -> Self {
56 self.notifications = true;
57 self
58 }
59
60 pub fn query_timeout(mut self, timeout: impl Into<Option<Duration>>) -> Self {
62 self.query_timeout = timeout.into();
63 self
64 }
65
66 pub fn transaction_timeout(mut self, timeout: impl Into<Option<Duration>>) -> Self {
68 self.transaction_timeout = timeout.into();
69 self
70 }
71
72 pub fn user(mut self, user: crate::opt::auth::Root<'_>) -> Self {
74 self.auth = Level::Root;
75 self.username = user.username.to_owned();
76 self.password = user.password.to_owned();
77 self
78 }
79
80 #[cfg(feature = "rustls")]
82 #[cfg_attr(docsrs, doc(cfg(feature = "rustls")))]
83 pub fn rustls(mut self, config: rustls::ClientConfig) -> Self {
84 self.tls_config = Some(super::Tls::Rust(config));
85 self
86 }
87
88 #[cfg(feature = "native-tls")]
90 #[cfg_attr(docsrs, doc(cfg(feature = "native-tls")))]
91 pub fn native_tls(mut self, config: native_tls::TlsConnector) -> Self {
92 self.tls_config = Some(super::Tls::Native(config));
93 self
94 }
95
96 pub fn tick_interval(mut self, interval: impl Into<Option<Duration>>) -> Self {
98 self.tick_interval = interval.into().filter(|x| !x.is_zero());
99 self
100 }
101
102 pub fn capabilities(mut self, capabilities: Capabilities) -> Self {
104 self.capabilities = capabilities;
105 self
106 }
107}