[][src]Struct sqlx::pool::PoolOptions

pub struct PoolOptions<DB> where
    DB: Database
{ /* fields omitted */ }

Implementations

impl<DB> PoolOptions<DB> where
    DB: Database
[src]

pub fn new() -> PoolOptions<DB>[src]

pub fn max_connections(self, max: u32) -> PoolOptions<DB>[src]

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

pub fn connect_timeout(self, timeout: Duration) -> PoolOptions<DB>[src]

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

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

pub fn min_connections(self, min: u32) -> PoolOptions<DB>[src]

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.

pub fn max_lifetime(
    self,
    lifetime: impl Into<Option<Duration>>
) -> PoolOptions<DB>
[src]

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.

pub fn idle_timeout(
    self,
    timeout: impl Into<Option<Duration>>
) -> PoolOptions<DB>
[src]

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.

pub fn test_before_acquire(self, test: bool) -> PoolOptions<DB>[src]

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

Defaults to true.

pub fn after_connect<F>(self, callback: F) -> PoolOptions<DB> where
    F: for<'c> Fn(&'c mut <DB as Database>::Connection) -> Pin<Box<dyn Future<Output = Result<(), Error>> + 'c + Send, Global>> + 'static + Send + Sync
[src]

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

pub fn before_acquire<F, Fut>(self, callback: F) -> PoolOptions<DB> where
    F: for<'c> Fn(&'c mut <DB as Database>::Connection) -> Pin<Box<dyn Future<Output = Result<bool, Error>> + 'c + Send, Global>> + 'static + Send + Sync
[src]

pub fn after_release<F, Fut>(self, callback: F) -> PoolOptions<DB> where
    F: Fn(&mut <DB as Database>::Connection) -> bool + 'static + Send + Sync
[src]

pub async fn connect(self, uri: &'_ str) -> Result<Pool<DB>, Error>[src]

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

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

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

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

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

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

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

Trait Implementations

impl<DB> Debug for PoolOptions<DB> where
    DB: Database
[src]

impl<DB> Default for PoolOptions<DB> where
    DB: Database
[src]

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

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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