Add examples to after_connect documentation

This requires testing with `--features postgres`.
This commit is contained in:
Joshua Nelson 2020-09-24 13:24:11 -04:00 committed by Ryan Leckey
parent 2be4601150
commit 920168a129

View File

@ -142,6 +142,26 @@ impl<DB: Database> PoolOptions<DB> {
self
}
/// Perform an action after connecting to the database.
///
/// # Example
///
/// ```no_run
/// # async fn f() -> Result<(), Box<dyn std::error::Error>> {
/// 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?;
/// # Ok(())
/// # }
/// ```
pub fn after_connect<F>(mut self, callback: F) -> Self
where
for<'c> F: