Struct PoolOpts

Source
pub struct PoolOpts { /* private fields */ }
Expand description

Connection pool options.

let pool_opts = PoolOpts::default()
    .with_constraints(PoolConstraints::new(15, 30).unwrap())
    .with_reset_connection(false);

Implementations§

Source§

impl PoolOpts

Source

pub fn new() -> Self

Calls Self::default.

Source

pub fn with_constraints(self, constraints: PoolConstraints) -> Self

Creates the default PoolOpts with the given constraints.

Source

pub fn constraints(&self) -> PoolConstraints

Returns pool constraints.

Source

pub fn with_reset_connection(self, reset_connection: bool) -> Self

Sets whether to reset the connection upon returning it to a pool (defaults to true).

Default behavior increases reliability but comes with cons:

  • reset procedure removes all prepared statements, i.e. kills prepared statements cache
  • connection reset is quite fast but requires additional client-server roundtrip (might require re-authentication for older servers)

The purpose of the reset procedure is to:

  • rollback any opened transactions
  • reset transaction isolation level
  • reset session variables
  • delete user variables
  • remove temporary tables
  • remove all PREPARE statement (this action kills prepared statements cache)

So to increase overall performance you can safely opt-out of the default behavior if you are not willing to change the session state in an unpleasant way.

It is also possible to selectively opt-in/out using crate::PooledConn::reset_connection.

§Connection URL

You can use reset_connection URL parameter to set this value. E.g.

let opts = Opts::from_url("mysql://localhost/db?reset_connection=false")?;
assert_eq!(opts.get_pool_opts().reset_connection(), false);
Source

pub fn reset_connection(&self) -> bool

Returns the reset_connection value (see PoolOpts::with_reset_connection).

Source

pub fn with_check_health(self, check_health: bool) -> Self

Sets whether to check connection health upon retrieving it from a pool (defaults to true).

If true, then Conn::ping will be invoked on a non-fresh pooled connection.

§Connection URL

Use check_health URL parameter to set this value. E.g.

let opts = Opts::from_url("mysql://localhost/db?check_health=false")?;
assert_eq!(opts.get_pool_opts().check_health(), false);
Source

pub fn check_health(&self) -> bool

Trait Implementations§

Source§

impl Clone for PoolOpts

Source§

fn clone(&self) -> PoolOpts

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PoolOpts

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for PoolOpts

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Hash for PoolOpts

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for PoolOpts

Source§

fn eq(&self, other: &PoolOpts) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for PoolOpts

Source§

impl StructuralPartialEq for PoolOpts

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T