mirror of
https://github.com/launchbadge/sqlx
synced 2024-11-10 14:34:19 +00:00
postgres: Add support for postgres:///?host=...
connection strings
This commit is contained in:
parent
fc78f15ebf
commit
a2673f7880
2 changed files with 8 additions and 2 deletions
|
@ -33,6 +33,7 @@ impl PgStream {
|
|||
.decode_utf8()
|
||||
.expect("percent-encoded hostname contained non-UTF-8 bytes")
|
||||
})
|
||||
.or_else(|| url.param("host"))
|
||||
.unwrap_or("/var/run/postgresql".into());
|
||||
if host.starts_with("/") {
|
||||
let path = format!("{}/.s.PGSQL.{}", host, port);
|
||||
|
|
|
@ -69,6 +69,7 @@ async fn try_upgrade(
|
|||
accept_invalid_host_names: bool,
|
||||
) -> crate::Result<bool> {
|
||||
use async_native_tls::TlsConnector;
|
||||
use std::borrow::Cow;
|
||||
|
||||
stream.write(crate::postgres::protocol::SslRequest);
|
||||
stream.flush().await?;
|
||||
|
@ -105,8 +106,12 @@ async fn try_upgrade(
|
|||
}
|
||||
}
|
||||
|
||||
let host = url.host().unwrap_or("localhost");
|
||||
stream.stream.upgrade(host, connector).await?;
|
||||
let host = url
|
||||
.host()
|
||||
.map(Cow::Borrowed)
|
||||
.or_else(|| url.param("host"))
|
||||
.unwrap_or("localhost".into());
|
||||
stream.stream.upgrade(&host, connector).await?;
|
||||
|
||||
Ok(true)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue