Struct sqlx_core::pool::PoolOptions

source ·
pub struct PoolOptions<DB: Database> { /* private fields */ }

Implementations§

source§

impl<DB: Database> PoolOptions<DB>

source

pub fn new() -> Self

source

pub fn max_connections(self, max: u32) -> Self

Set the maximum number of connections that this pool should maintain.

source

pub fn connect_timeout(self, timeout: Duration) -> Self

Set the amount of time to attempt connecting to the database.

If this timeout elapses, Pool::acquire will return an error.

source

pub fn min_connections(self, min: u32) -> Self

Set the minimum number of connections to maintain at all times.

When the pool is built, this many connections will be automatically spun up.

If any connection is reaped by max_lifetime or idle_timeout and it brings the connection count below this amount, a new connection will be opened to replace it.

source

pub fn max_lifetime(self, lifetime: impl Into<Option<Duration>>) -> Self

Set the maximum lifetime of individual connections.

Any connection with a lifetime greater than this will be closed.

When set to None, all connections live until either reaped by idle_timeout or explicitly disconnected.

Infinite connections are not recommended due to the unfortunate reality of memory/resource leaks on the database-side. It is better to retire connections periodically (even if only once daily) to allow the database the opportunity to clean up data structures (parse trees, query metadata caches, thread-local storage, etc.) that are associated with a session.

source

pub fn idle_timeout(self, timeout: impl Into<Option<Duration>>) -> Self

Set a maximum idle duration for individual connections.

Any connection with an idle duration longer than this will be closed.

For usage-based database server billing, this can be a cost saver.

source

pub fn test_before_acquire(self, test: bool) -> Self

If true, the health of a connection will be verified by a call to Connection::ping before returning the connection.

Defaults to true.

source

pub fn after_connect<F>(self, callback: F) -> Self
where for<'c> F: Fn(&'c mut DB::Connection) -> BoxFuture<'c, Result<(), Error>> + 'static + Send + Sync,

Perform an action after connecting to the database.

Example
use sqlx_core::executor::Executor;
use sqlx_core::postgres::PgPoolOptions;
// PostgreSQL
let pool = PgPoolOptions::new()
    .after_connect(|conn| Box::pin(async move {
       conn.execute("SET application_name = 'your_app';").await?;
       conn.execute("SET search_path = 'my_schema';").await?;

       Ok(())
    }))
    .connect("postgres:// …").await?;
source

pub fn before_acquire<F>(self, callback: F) -> Self
where for<'c> F: Fn(&'c mut DB::Connection) -> BoxFuture<'c, Result<bool, Error>> + 'static + Send + Sync,

source

pub fn after_release<F>(self, callback: F) -> Self
where F: Fn(&mut DB::Connection) -> bool + 'static + Send + Sync,

source

pub async fn connect(self, uri: &str) -> Result<Pool<DB>, Error>

Creates a new pool from this configuration and immediately establishes one connection.

source

pub async fn connect_with( self, options: <DB::Connection as Connection>::Options ) -> Result<Pool<DB>, Error>

Creates a new pool from this configuration and immediately establishes one connection.

source

pub fn connect_lazy(self, uri: &str) -> Result<Pool<DB>, Error>

Creates a new pool from this configuration and will establish a connections as the pool starts to be used.

source

pub fn connect_lazy_with( self, options: <DB::Connection as Connection>::Options ) -> Pool<DB>

Creates a new pool from this configuration and will establish a connections as the pool starts to be used.

Trait Implementations§

source§

impl<DB: Database> Debug for PoolOptions<DB>

source§

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

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

impl<DB: Database> Default for PoolOptions<DB>

source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<DB> !RefUnwindSafe for PoolOptions<DB>

§

impl<DB> Send for PoolOptions<DB>

§

impl<DB> Sync for PoolOptions<DB>

§

impl<DB> Unpin for PoolOptions<DB>

§

impl<DB> !UnwindSafe for PoolOptions<DB>

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> 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

§

type Output = T

Should always be Self
source§

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

§

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>,

§

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