Skip to content
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

Add pool_constraints method to OptsBuilder to set pool_min and pool_max #368

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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/conn/opts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,23 @@ impl OptsBuilder {
Ok(self)
}

/// Pool constraints (pool_min and pool_max). Passing None to one or the
/// other preserves the default value(s) (defaults to 10 and 100 resp.)
pub fn pool_constraints(mut self, pool_min: Option<usize>, pool_max: Option<usize>) -> Result<Self, UrlError> {
let pool_min = pool_min.unwrap_or(PoolConstraints::DEFAULT.min());
let pool_max = pool_max.unwrap_or(PoolConstraints::DEFAULT.max());

if let Some(pool_constraints) = PoolConstraints::new(pool_min, pool_max) {
self.opts.0.pool_opts = self.opts.0.pool_opts.with_constraints(pool_constraints);
} else {
return Err(UrlError::InvalidPoolConstraints {
min: pool_min,
max: pool_max,
});
}
Ok(self)
}

/// Address of mysql server (defaults to `127.0.0.1`). Hostnames should also work.
///
/// **Note:** IPv6 addresses must be given in square brackets, e.g. `[::1]`.
Expand Down
Loading