mirror of
https://github.com/launchbadge/sqlx.git
synced 2026-03-23 18:40:24 +00:00
doc: make it clear that ConnectOptions types impl FromStr (#2574)
This commit is contained in:
@@ -23,6 +23,9 @@ mod ssl_mode;
|
||||
/// postgresql://[user[:password]@][host][:port][/dbname][?param1=value1&...]
|
||||
/// ```
|
||||
///
|
||||
/// This type also implements [`FromStr`][std::str::FromStr] so you can parse it from a string
|
||||
/// containing a connection URL and then further adjust options if necessary (see example below).
|
||||
///
|
||||
/// ## Parameters
|
||||
///
|
||||
/// |Parameter|Default|Description|
|
||||
@@ -55,13 +58,10 @@ mod ssl_mode;
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust,no_run
|
||||
/// # use sqlx_core::error::Error;
|
||||
/// # use sqlx_core::connection::{Connection, ConnectOptions};
|
||||
/// # use sqlx_core::postgres::{PgConnectOptions, PgConnection, PgSslMode};
|
||||
/// #
|
||||
/// # fn main() {
|
||||
/// # #[cfg(feature = "_rt")]
|
||||
/// # sqlx::__rt::test_block_on(async move {
|
||||
/// use sqlx::{Connection, ConnectOptions};
|
||||
/// use sqlx::postgres::{PgConnectOptions, PgConnection, PgPool, PgSslMode};
|
||||
///
|
||||
/// # async fn example() -> sqlx::Result<()> {
|
||||
/// // URL connection string
|
||||
/// let conn = PgConnection::connect("postgres://localhost/mydb").await?;
|
||||
///
|
||||
@@ -72,9 +72,17 @@ mod ssl_mode;
|
||||
/// .username("secret-user")
|
||||
/// .password("secret-password")
|
||||
/// .ssl_mode(PgSslMode::Require)
|
||||
/// .connect().await?;
|
||||
/// # Result::<(), Error>::Ok(())
|
||||
/// # }).unwrap();
|
||||
/// .connect()
|
||||
/// .await?;
|
||||
///
|
||||
/// // Modifying options parsed from a string
|
||||
/// let mut opts: PgConnectOptions = "postgres://localhost/mydb".parse()?;
|
||||
///
|
||||
/// // Change the log verbosity level for queries.
|
||||
/// // Information about SQL queries is logged at `DEBUG` level by default.
|
||||
/// opts.log_statements(log::LevelFilter::Trace);
|
||||
///
|
||||
/// let pool = PgPool::connect_with(&opts).await?;
|
||||
/// # }
|
||||
/// ```
|
||||
#[derive(Debug, Clone)]
|
||||
|
||||
Reference in New Issue
Block a user