Skip to content

Commit 8c124d5

Browse files
committed
Accept passfile connection option
1 parent 4741e92 commit 8c124d5

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

sqlx-postgres/src/options/parse.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::{PgConnectOptions, PgSslMode};
33
use sqlx_core::percent_encoding::{percent_decode_str, utf8_percent_encode, NON_ALPHANUMERIC};
44
use sqlx_core::Url;
55
use std::net::IpAddr;
6+
use std::path::PathBuf;
67
use std::str::FromStr;
78

89
impl PgConnectOptions {
@@ -87,6 +88,8 @@ impl PgConnectOptions {
8788

8889
"password" => options = options.password(&value),
8990

91+
"passfile" => options.passfile_paths.insert(0, PathBuf::from(&*value)),
92+
9093
"application_name" => options = options.application_name(&value),
9194

9295
"options" => {
@@ -242,6 +245,20 @@ fn it_parses_password_correctly_from_parameter() {
242245
assert_eq!(Some("some_pass"), opts.password.as_deref());
243246
}
244247

248+
#[test]
249+
fn it_parses_passfile_correctly_from_parameter() {
250+
let url = "postgres:///?passfile=/non%20default/pgpass&passfile=.pgpass";
251+
let opts = PgConnectOptions::from_str(url).unwrap();
252+
253+
assert_eq!(
254+
vec![
255+
PathBuf::from(".pgpass"),
256+
PathBuf::from("/non default/pgpass"),
257+
],
258+
opts.passfile_paths
259+
);
260+
}
261+
245262
#[test]
246263
fn it_parses_application_name_correctly_from_parameter() {
247264
let url = "postgres:///?application_name=some_name";

0 commit comments

Comments
 (0)