We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent f3fe41e commit 57f52ffCopy full SHA for 57f52ff
sqlx-core/src/postgres/connection.rs
@@ -110,8 +110,12 @@ pub struct PgConnection {
110
111
// https://www.postgresql.org/docs/12/protocol-flow.html#id-1.10.5.7.3
112
async fn startup(stream: &mut PgStream, url: &Url) -> crate::Result<BackendKeyData> {
113
- // Defaults to postgres@.../postgres
114
- let username = url.username().unwrap_or(Cow::Borrowed("postgres"));
+ // Defaults to $USER@.../$USER
+ // and falls back to postgres@.../postgres
115
+ let username = url
116
+ .username()
117
+ .or_else(|| std::env::var("USER").map(Cow::Owned).ok())
118
+ .unwrap_or(Cow::Borrowed("postgres"));
119
let database = url.database().unwrap_or(&username);
120
121
// See this doc for more runtime parameters
0 commit comments