pub struct DatabaseConfig {
pub host: String,
pub port: u16,
pub username: String,
pub password: String,
pub database: String,
pub max_open_cons: u32,
pub min_idle_cons: u32,
pub conn_max_lifetime: Duration,
pub connection_timeout: Duration,
pub idle_timeout: Duration,
}Expand description
DatabaseConfig represents the configuration for connecting to a database.
This configuration object can be used to set up a connection pool
to PostgreSQL or another sqlx-supported database.
Configuration fields can be loaded from various sources, such as YAML, JSON configuration files, or from environment variables.
Example configuration in YAML:
host: localhost
port: 5432
username: user
password: password
database: test
max_open_cons: 10
min_idle_cons: 5
conn_max_lifetime:
secs: 900
nanos: 0
connection_timeout:
secs: 15
nanos: 0
idle_timeout:
secs: 3600
nanos: 0Fields§
§host: StringThe database host address (e.g. localhost).
port: u16The port to connect to the database (e.g. 5432 for PostgreSQL).
username: StringThe username to connect to the database.
password: StringThe password to connect to the database.
database: StringThe name of the database to connect to.
max_open_cons: u32The maximum number of open connections in the pool.
min_idle_cons: u32The minimum number of idle connections in the pool.
conn_max_lifetime: DurationThe maximum connection lifetime.
connection_timeout: DurationThe timeout for getting a connection from the pool.
idle_timeout: DurationThe idle connection timeout in the pool, after which the connection can be closed.
Trait Implementations§
source§impl Debug for DatabaseConfig
impl Debug for DatabaseConfig
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>,
Auto Trait Implementations§
impl Freeze for DatabaseConfig
impl RefUnwindSafe for DatabaseConfig
impl Send for DatabaseConfig
impl Sync for DatabaseConfig
impl Unpin 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
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 more