+
Skip to content

Add max_lifetime connection option #493

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 5, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/database/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ pub struct ConnectOptions {
/// Maximum idle time for a particular connection to prevent
/// network resource exhaustion
pub(crate) idle_timeout: Option<Duration>,
/// Set the maximum lifetime of individual connections
pub(crate) max_lifetime: Option<Duration>,
/// Enable SQLx statement logging
pub(crate) sqlx_logging: bool,
}
Expand Down Expand Up @@ -100,6 +102,7 @@ impl ConnectOptions {
min_connections: None,
connect_timeout: None,
idle_timeout: None,
max_lifetime: None,
sqlx_logging: true,
}
}
Expand Down Expand Up @@ -127,6 +130,9 @@ impl ConnectOptions {
if let Some(idle_timeout) = self.idle_timeout {
opt = opt.idle_timeout(Some(idle_timeout));
}
if let Some(max_lifetime) = self.max_lifetime {
opt = opt.max_lifetime(Some(max_lifetime));
}
opt
}

Expand Down Expand Up @@ -179,6 +185,17 @@ impl ConnectOptions {
self.idle_timeout
}

/// Set the maximum lifetime of individual connections
pub fn max_lifetime(&mut self, lifetime: Duration) -> &mut Self {
self.max_lifetime = Some(lifetime);
self
}

/// Get the maximum lifetime of individual connections, if set
pub fn get_max_lifetime(&self) -> Option<Duration> {
self.max_lifetime
}

/// Enable SQLx statement logging (default true)
pub fn sqlx_logging(&mut self, value: bool) -> &mut Self {
self.sqlx_logging = value;
Expand Down
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载