rocket_db_pools::diesel

Type Alias Pool

Source
pub type Pool<C> = Pool<AsyncDieselConnectionManager<C>>;
Expand description

Type alias for using deadpool::managed::Pool with [diesel-async]

Aliased Type§

struct Pool<C> { /* private fields */ }

Implementations

Source§

impl<M, W> Pool<M, W>
where M: Manager, W: From<Object<M>>,

Source

pub fn builder(manager: M) -> PoolBuilder<M, W>

Instantiates a builder for a new Pool.

This is the only way to create a Pool instance.

Source

pub async fn get(&self) -> Result<W, PoolError<<M as Manager>::Error>>

Retrieves an Object from this Pool or waits for one to become available.

§Errors

See PoolError for details.

Source

pub async fn try_get(&self) -> Result<W, PoolError<<M as Manager>::Error>>

👎Deprecated since 0.9.3: The name of this method is highly misleading. Please use timeout_get instead. e.g. pool.timeout_get(&Timeouts { wait: Some(Duration::ZERO), ..pool.timeouts() })

Retrieves an Object from this Pool and doesn’t wait if there is currently no Object available and the maximum Pool size has been reached.

§Errors

See PoolError for details.

Source

pub async fn timeout_get( &self, timeouts: &Timeouts, ) -> Result<W, PoolError<<M as Manager>::Error>>

Retrieves an Object from this Pool using a different timeout than the configured one.

§Errors

See PoolError for details.

Source

pub fn resize(&self, max_size: usize)

Resize the pool. This change the max_size of the pool dropping excess objects and/or making space for new ones.

If the pool is closed this method does nothing. The Pool::status method always reports a max_size of 0 for closed pools.

Source

pub fn retain(&self, f: impl Fn(&<M as Manager>::Type, Metrics) -> bool)

Retains only the objects specified by the given function.

This function is typically used to remove objects from the pool based on their current state or metrics.

Caution: This function blocks the entire pool while it is running. Therefore the given function should not block.

The following example starts a background task that runs every 30 seconds and removes objects from the pool that haven’t been used for more than one minute.

let interval = Duration::from_secs(30);
let max_age = Duration::from_secs(60);
tokio::spawn(async move {
    loop {
        tokio::time::sleep(interval).await;
        pool.retain(|_, metrics| metrics.last_used() < max_age);
    }
});
Source

pub fn timeouts(&self) -> Timeouts

Get current timeout configuration

Source

pub fn close(&self)

Closes this Pool.

All current and future tasks waiting for Objects will return PoolError::Closed immediately.

This operation resizes the pool to 0.

Source

pub fn is_closed(&self) -> bool

Indicates whether this Pool has been closed.

Source

pub fn status(&self) -> Status

Retrieves Status of this Pool.

Source

pub fn manager(&self) -> &M

Returns Manager of this Pool.

Trait Implementations

Source§

impl<M, W> Clone for Pool<M, W>
where M: Manager, W: From<Object<M>>,

Source§

fn clone(&self) -> Pool<M, W>

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<M, W> Debug for Pool<M, W>
where M: Debug + Manager, <M as Manager>::Type: Debug, W: From<Object<M>>,

Source§

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

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

impl<M: DeadManager, C> Pool for Pool<M, C>
where M::Type: Send, C: Send + Sync + 'static + From<Object<M>>, M::Error: Error,

Source§

type Error = Error<BuildError<<M as Manager>::Error>, PoolError<<M as Manager>::Error>>

The error type returned by Self::init() and Self::get().
Source§

type Connection = C

The connection type managed by this pool, returned by Self::get().
Source§

fn init<'life0, 'async_trait>( figment: &'life0 Figment, ) -> Pin<Box<dyn Future<Output = Result<Self, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Constructs a pool from a Value. Read more
Source§

fn get<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Self::Connection, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Asynchronously retrieves a connection from the factory or pool. Read more
Source§

fn close<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Shutdown the connection pool, disallowing any new connections from being retrieved and waking up any tasks with active connections. Read more