pub struct ConnectionConfig {
pub db_url: String,
pub db_ns: String,
pub db: String,
pub db_user: Option<String>,
pub db_pass: Option<String>,
pub db_timeout: f64,
pub db_max_connections: u32,
pub db_retry_max_attempts: u32,
pub db_retry_min_wait: f64,
pub db_retry_max_wait: f64,
pub db_retry_multiplier: f64,
pub enable_live_queries: bool,
}Expand description
Database connection configuration.
Field names follow the Python port (db_url, db_ns, db, …) for
wire-compatibility with env-var loading; convenient getters are
provided for the shorter aliases (url, namespace, database, …).
§Examples
use surql::connection::ConnectionConfig;
let cfg = ConnectionConfig::builder()
.url("ws://localhost:8000/rpc")
.namespace("prod")
.database("app")
.build()
.unwrap();
assert_eq!(cfg.url(), "ws://localhost:8000/rpc");
assert_eq!(cfg.namespace(), "prod");
assert_eq!(cfg.database(), "app");Fields§
§db_url: StringSurrealDB connection URL. Aliases: url.
db_ns: StringDatabase namespace. Aliases: namespace.
db: StringDatabase name. Aliases: database.
db_user: Option<String>Authentication username. Aliases: username.
db_pass: Option<String>Authentication password. Aliases: password.
db_timeout: f64Connection timeout in seconds. Aliases: timeout.
db_max_connections: u32Maximum number of concurrent connections. Aliases: max_connections.
db_retry_max_attempts: u32Maximum retry attempts. Aliases: retry_max_attempts.
db_retry_min_wait: f64Minimum retry wait time in seconds. Aliases: retry_min_wait.
db_retry_max_wait: f64Maximum retry wait time in seconds. Aliases: retry_max_wait.
db_retry_multiplier: f64Exponential backoff multiplier. Aliases: retry_multiplier.
enable_live_queries: boolEnable live query support. Requires WebSocket or embedded URL.
Implementations§
Source§impl ConnectionConfig
impl ConnectionConfig
Sourcepub fn builder() -> ConnectionConfigBuilder
pub fn builder() -> ConnectionConfigBuilder
Start a builder with the default field values.
Sourcepub fn validate(&self) -> Result<()>
pub fn validate(&self) -> Result<()>
Validate the configuration values according to the Python port’s rules.
Sourcepub fn protocol(&self) -> Result<Protocol>
pub fn protocol(&self) -> Result<Protocol>
Infer the Protocol used by this configuration’s URL.
Sourcepub fn from_env() -> Result<Self>
pub fn from_env() -> Result<Self>
Load configuration from environment variables prefixed SURQL_.
Recognised variables (case-insensitive): SURQL_URL,
SURQL_NAMESPACE, SURQL_DATABASE, SURQL_USERNAME,
SURQL_PASSWORD, SURQL_TIMEOUT, SURQL_MAX_CONNECTIONS,
SURQL_RETRY_MAX_ATTEMPTS, SURQL_RETRY_MIN_WAIT,
SURQL_RETRY_MAX_WAIT, SURQL_RETRY_MULTIPLIER,
SURQL_ENABLE_LIVE_QUERIES.
Missing values fall back to ConnectionConfig::default; on
success, the built config is validated before return.
Sourcepub fn from_env_with_prefix(prefix: &str) -> Result<Self>
pub fn from_env_with_prefix(prefix: &str) -> Result<Self>
Load configuration from environment variables with a custom prefix
(e.g. SURQL_PRIMARY_ for named connections).
Sourcepub fn from_source_with_prefix<F>(prefix: &str, lookup: F) -> Result<Self>
pub fn from_source_with_prefix<F>(prefix: &str, lookup: F) -> Result<Self>
Build a config from an arbitrary key lookup (used by Self::from_env
and by tests to avoid process-wide env mutation).
lookup is called with the fully-qualified variable name (case
preserved). Missing values fall back to defaults.
Sourcepub fn from_map_with_prefix(
prefix: &str,
map: &HashMap<String, String>,
) -> Result<Self>
pub fn from_map_with_prefix( prefix: &str, map: &HashMap<String, String>, ) -> Result<Self>
Convenience: build from a pre-populated map (useful in tests).
Sourcepub fn url(&self) -> &str
pub fn url(&self) -> &str
Alias for Self::db_url.
Sourcepub fn namespace(&self) -> &str
pub fn namespace(&self) -> &str
Alias for Self::db_ns.
Sourcepub fn username(&self) -> Option<&str>
pub fn username(&self) -> Option<&str>
Alias for Self::db_user.
Sourcepub fn password(&self) -> Option<&str>
pub fn password(&self) -> Option<&str>
Alias for Self::db_pass.
Sourcepub fn timeout(&self) -> f64
pub fn timeout(&self) -> f64
Alias for Self::db_timeout.
Sourcepub fn max_connections(&self) -> u32
pub fn max_connections(&self) -> u32
Alias for Self::db_max_connections.
Sourcepub fn retry_max_attempts(&self) -> u32
pub fn retry_max_attempts(&self) -> u32
Alias for Self::db_retry_max_attempts.
Sourcepub fn retry_min_wait(&self) -> f64
pub fn retry_min_wait(&self) -> f64
Alias for Self::db_retry_min_wait.
Sourcepub fn retry_max_wait(&self) -> f64
pub fn retry_max_wait(&self) -> f64
Alias for Self::db_retry_max_wait.
Sourcepub fn retry_multiplier(&self) -> f64
pub fn retry_multiplier(&self) -> f64
Alias for Self::db_retry_multiplier.
Trait Implementations§
Source§impl Clone for ConnectionConfig
impl Clone for ConnectionConfig
Source§fn clone(&self) -> ConnectionConfig
fn clone(&self) -> ConnectionConfig
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ConnectionConfig
impl Debug for ConnectionConfig
Source§impl Default for ConnectionConfig
impl Default for ConnectionConfig
Source§impl<'de> Deserialize<'de> for ConnectionConfig
impl<'de> Deserialize<'de> for ConnectionConfig
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl PartialEq for ConnectionConfig
impl PartialEq for ConnectionConfig
Source§impl Serialize for ConnectionConfig
impl Serialize for ConnectionConfig
impl StructuralPartialEq for ConnectionConfig
Auto Trait Implementations§
impl Freeze for ConnectionConfig
impl RefUnwindSafe for ConnectionConfig
impl Send for ConnectionConfig
impl Sync for ConnectionConfig
impl Unpin for ConnectionConfig
impl UnsafeUnpin for ConnectionConfig
impl UnwindSafe for ConnectionConfig
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request