pub struct DatabaseConfig {
pub url: String,
pub max_connections: u32,
pub timeout_seconds: u64,
pub enable_logging: bool,
}Expand description
Database configuration with connection examples
Fields§
§url: StringDatabase connection URL
max_connections: u32Maximum number of connections in the pool
timeout_seconds: u64Connection timeout in seconds
enable_logging: boolWhether to enable SQL query logging
Implementations§
Source§impl DatabaseConfig
impl DatabaseConfig
Sourcepub fn builder() -> DatabaseConfigBuilder
pub fn builder() -> DatabaseConfigBuilder
Create an instance of DatabaseConfig using the builder syntax
Source§impl DatabaseConfig
impl DatabaseConfig
Sourcepub fn examples() -> HashMap<&'static str, Self>
pub fn examples() -> HashMap<&'static str, Self>
Example configurations for different environments and databases
Sourcepub fn from_env() -> Result<Self, VarError>
pub fn from_env() -> Result<Self, VarError>
Create a new configuration from environment variables
Expected environment variables:
DATABASE_URL: Required - the database connection URLDATABASE_MAX_CONNECTIONS: Optional - defaults to 10DATABASE_TIMEOUT_SECONDS: Optional - defaults to 30DATABASE_ENABLE_LOGGING: Optional - defaults to false
Sourcepub fn database_type(&self) -> Option<DatabaseType>
pub fn database_type(&self) -> Option<DatabaseType>
Get the database type from the URL.
Returns None if the URL scheme is not recognized.
Sourcepub fn validate_database_support(&self) -> Result<DatabaseType, String>
pub fn validate_database_support(&self) -> Result<DatabaseType, String>
Validate that the database URL scheme matches a compiled feature.
Returns an error if the URL scheme is unrecognized or if the corresponding feature flag is not enabled.
Trait Implementations§
Source§impl Clone for DatabaseConfig
impl Clone for DatabaseConfig
Source§fn clone(&self) -> DatabaseConfig
fn clone(&self) -> DatabaseConfig
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for DatabaseConfig
impl Debug for DatabaseConfig
Source§impl Default for DatabaseConfig
Available on crate feature sqlx-storage only.
impl Default for DatabaseConfig
Available on crate feature
sqlx-storage only.Source§impl<'de> Deserialize<'de> for DatabaseConfig
impl<'de> Deserialize<'de> for DatabaseConfig
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>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for DatabaseConfig
impl RefUnwindSafe for DatabaseConfig
impl Send for DatabaseConfig
impl Sync for DatabaseConfig
impl Unpin for DatabaseConfig
impl UnsafeUnpin for DatabaseConfig
impl UnwindSafe for DatabaseConfig
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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> ⓘ
Converts
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> ⓘ
Converts
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 more