pub struct Hooks { /* private fields */ }Expand description
Optional pool hooks.
Use this with Pool::with_hooks when you want connection setup or
validation around pool checkout.
This stays empty by default:
quex::Hooks::new();A more typical setup looks like this:
quex::Hooks::new()
.on_connect(|conn| Box::pin(async move {
conn.query("create table if not exists users(id integer primary key)")
.await?;
Ok(())
}))
.before_acquire(|conn| Box::pin(async move {
conn.query("select 1").await?;
Ok(quex::AcquireDecision::Accept)
}));Implementations§
Source§impl Hooks
impl Hooks
Sourcepub fn on_connect<F>(self, hook: F) -> Hooks
pub fn on_connect<F>(self, hook: F) -> Hooks
Runs after the pool opens a fresh connection.
Use this for setup that should happen once per new connection.
This does not run when the pool reuses an idle connection.
Sourcepub fn before_acquire<F>(self, hook: F) -> Hooks
pub fn before_acquire<F>(self, hook: F) -> Hooks
Runs before the pool returns a checked-out connection.
Use this to validate the connection and decide whether the pool should hand it out or discard it and try again.
Return AcquireDecision::Accept to hand the connection to the
caller, or AcquireDecision::Retry to discard this candidate and let
the pool try another one.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Hooks
impl !RefUnwindSafe for Hooks
impl Send for Hooks
impl Sync for Hooks
impl Unpin for Hooks
impl UnsafeUnpin for Hooks
impl !UnwindSafe for Hooks
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more