mirror of
https://github.com/launchbadge/sqlx.git
synced 2025-10-02 07:21:08 +00:00
Decide host
parameter between host and socket
- If starts with a leading `/`, use socket - If not, use host
This commit is contained in:
parent
868dc3dd5b
commit
0ccfab1f25
@ -395,7 +395,11 @@ impl FromStr for PgConnectOptions {
|
||||
}
|
||||
|
||||
"host" => {
|
||||
options = options.socket(&*value);
|
||||
if value.starts_with("/") {
|
||||
options = options.socket(&*value);
|
||||
} else {
|
||||
options = options.host(&*value);
|
||||
}
|
||||
}
|
||||
|
||||
_ => {}
|
||||
@ -405,3 +409,25 @@ impl FromStr for PgConnectOptions {
|
||||
Ok(options)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn parses_socket_correctly_from_parameter() {
|
||||
let uri = "postgres:///?host=/var/run/postgres/";
|
||||
let opts = PgConnectOptions::from_str(uri).unwrap();
|
||||
|
||||
assert_eq!(Some("/var/run/postgres/".into()), opts.socket);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parses_host_correctly_from_parameter() {
|
||||
let uri = "postgres:///?host=google.database.com";
|
||||
let opts = PgConnectOptions::from_str(uri).unwrap();
|
||||
|
||||
assert_eq!(None, opts.socket);
|
||||
assert_eq!("google.database.com", &opts.host);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user