@@ -23,6 +23,9 @@ mod ssl_mode;
23
23
/// postgresql://[user[:password]@][host][:port][/dbname][?param1=value1&...]
24
24
/// ```
25
25
///
26
+ /// This type also implements [`FromStr`][std::str::FromStr] so you can parse it from a string
27
+ /// containing a connection URL and then further adjust options if necessary (see example below).
28
+ ///
26
29
/// ## Parameters
27
30
///
28
31
/// |Parameter|Default|Description|
@@ -55,13 +58,10 @@ mod ssl_mode;
55
58
/// # Example
56
59
///
57
60
/// ```rust,no_run
58
- /// # use sqlx_core::error::Error;
59
- /// # use sqlx_core::connection::{Connection, ConnectOptions};
60
- /// # use sqlx_core::postgres::{PgConnectOptions, PgConnection, PgSslMode};
61
- /// #
62
- /// # fn main() {
63
- /// # #[cfg(feature = "_rt")]
64
- /// # sqlx::__rt::test_block_on(async move {
61
+ /// use sqlx::{Connection, ConnectOptions};
62
+ /// use sqlx::postgres::{PgConnectOptions, PgConnection, PgPool, PgSslMode};
63
+ ///
64
+ /// # async fn example() -> sqlx::Result<()> {
65
65
/// // URL connection string
66
66
/// let conn = PgConnection::connect("postgres://localhost/mydb").await?;
67
67
///
@@ -72,9 +72,17 @@ mod ssl_mode;
72
72
/// .username("secret-user")
73
73
/// .password("secret-password")
74
74
/// .ssl_mode(PgSslMode::Require)
75
- /// .connect().await?;
76
- /// # Result::<(), Error>::Ok(())
77
- /// # }).unwrap();
75
+ /// .connect()
76
+ /// .await?;
77
+ ///
78
+ /// // Modifying options parsed from a string
79
+ /// let mut opts: PgConnectOptions = "postgres://localhost/mydb".parse()?;
80
+ ///
81
+ /// // Change the log verbosity level for queries.
82
+ /// // Information about SQL queries is logged at `DEBUG` level by default.
83
+ /// opts.log_statements(log::LevelFilter::Trace);
84
+ ///
85
+ /// let pool = PgPool::connect_with(&opts).await?;
78
86
/// # }
79
87
/// ```
80
88
#[ derive( Debug , Clone ) ]
0 commit comments