surrealdb/api/opt/
config.rsuse crate::opt::capabilities::Capabilities;
#[cfg(storage)]
use std::path::PathBuf;
use std::time::Duration;
use surrealdb_core::{dbs::Capabilities as CoreCapabilities, iam::Level};
#[derive(Debug, Clone, Default)]
pub struct Config {
pub(crate) strict: bool,
pub(crate) ast_payload: bool,
pub(crate) query_timeout: Option<Duration>,
pub(crate) transaction_timeout: Option<Duration>,
#[cfg(any(feature = "native-tls", feature = "rustls"))]
pub(crate) tls_config: Option<super::Tls>,
pub(crate) auth: Level,
pub(crate) username: String,
pub(crate) password: String,
pub(crate) capabilities: CoreCapabilities,
#[cfg(storage)]
pub(crate) temporary_directory: Option<PathBuf>,
pub(crate) node_membership_refresh_interval: Option<Duration>,
pub(crate) node_membership_check_interval: Option<Duration>,
pub(crate) node_membership_cleanup_interval: Option<Duration>,
pub(crate) changefeed_gc_interval: Option<Duration>,
}
impl Config {
pub fn new() -> Self {
Default::default()
}
pub fn set_strict(mut self, strict: bool) -> Self {
self.strict = strict;
self
}
pub fn strict(mut self) -> Self {
self.strict = true;
self
}
pub fn set_ast_payload(mut self, ast_payload: bool) -> Self {
self.ast_payload = ast_payload;
self
}
pub fn ast_payload(mut self) -> Self {
self.ast_payload = true;
self
}
pub fn query_timeout(mut self, timeout: impl Into<Option<Duration>>) -> Self {
self.query_timeout = timeout.into();
self
}
pub fn transaction_timeout(mut self, timeout: impl Into<Option<Duration>>) -> Self {
self.transaction_timeout = timeout.into();
self
}
pub fn user(mut self, user: crate::opt::auth::Root<'_>) -> Self {
self.auth = Level::Root;
user.username.clone_into(&mut self.username);
user.password.clone_into(&mut self.password);
self
}
#[cfg(feature = "rustls")]
#[cfg_attr(docsrs, doc(cfg(feature = "rustls")))]
pub fn rustls(mut self, config: rustls::ClientConfig) -> Self {
self.tls_config = Some(super::Tls::Rust(config));
self
}
#[cfg(feature = "native-tls")]
#[cfg_attr(docsrs, doc(cfg(feature = "native-tls")))]
pub fn native_tls(mut self, config: native_tls::TlsConnector) -> Self {
self.tls_config = Some(super::Tls::Native(config));
self
}
pub fn capabilities(mut self, capabilities: Capabilities) -> Self {
self.capabilities = capabilities.build();
self
}
#[doc(hidden)]
pub fn get_capabilities(&self) -> &CoreCapabilities {
&self.capabilities
}
#[cfg(storage)]
pub fn temporary_directory(mut self, path: Option<PathBuf>) -> Self {
self.temporary_directory = path;
self
}
pub fn node_membership_refresh_interval(
mut self,
interval: impl Into<Option<Duration>>,
) -> Self {
self.node_membership_refresh_interval = interval.into().filter(|x| !x.is_zero());
self
}
pub fn node_membership_check_interval(mut self, interval: impl Into<Option<Duration>>) -> Self {
self.node_membership_check_interval = interval.into().filter(|x| !x.is_zero());
self
}
pub fn node_membership_cleanup_interval(
mut self,
interval: impl Into<Option<Duration>>,
) -> Self {
self.node_membership_cleanup_interval = interval.into().filter(|x| !x.is_zero());
self
}
pub fn changefeed_gc_interval(mut self, interval: impl Into<Option<Duration>>) -> Self {
self.changefeed_gc_interval = interval.into().filter(|x| !x.is_zero());
self
}
}