From 920168a129e7b7272969acc16a531f9e3f1d1054 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Thu, 24 Sep 2020 13:24:11 -0400 Subject: [PATCH] Add examples to `after_connect` documentation This requires testing with `--features postgres`. --- sqlx-core/src/pool/options.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/sqlx-core/src/pool/options.rs b/sqlx-core/src/pool/options.rs index a8d5d168..ff12968d 100644 --- a/sqlx-core/src/pool/options.rs +++ b/sqlx-core/src/pool/options.rs @@ -142,6 +142,26 @@ impl PoolOptions { self } + /// Perform an action after connecting to the database. + /// + /// # Example + /// + /// ```no_run + /// # async fn f() -> Result<(), Box> { + /// 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(mut self, callback: F) -> Self where for<'c> F: