Skip to main content

siderite_backends/
connection_init.rs

1//! Explicit composition of SQLx connection initialization.
2//!
3//! PoolOptions stores its after_connect callback privately. Constructors
4//! cannot recover or transparently chain a callback already installed there.
5//! Pass custom setup explicitly; adapters run it before mandatory settings.
6
7use sqlx::Database;
8use sqlx::pool::PoolConnectionMetadata;
9use std::future::Future;
10use std::pin::Pin;
11use std::sync::Arc;
12
13type Outcome = Result<(), sqlx::Error>;
14type Conn<DB> = <DB as Database>::Connection;
15type Meta = PoolConnectionMetadata;
16
17type Pinned<'a> = Pin<Box<dyn Future<Output = Outcome> + Send + 'a>>;
18/// Borrowed connection initialization future.
19pub type InitFuture<'a> = Pinned<'a>;
20
21/// Shared custom callback invoked on every fresh physical connection.
22///
23/// Return an error to reject the connection; SQLx closes it and retries
24/// within its acquisition deadline. Leave no transaction or lock open.
25/// Mandatory adapter settings run afterwards and may override conflicting
26/// values. Callback messages are subject to SQLx's own error logging.
27pub type ConnectionInit<DB> =
28    Arc<dyn for<'a> Fn(&'a mut Conn<DB>, Meta) -> Pinned<'a> + Send + Sync>;