mirror of
https://github.com/launchbadge/sqlx.git
synced 2025-12-30 05:11:13 +00:00
feat: parse additional parameters: user, password, port, dbname. Also
add additional documentation and an example connection string using parameters.
This commit is contained in:
parent
1f41e4c54d
commit
d0ccb4d0b2
@ -26,6 +26,11 @@ pub use ssl_mode::PgSslMode;
|
||||
/// | `sslrootcert` | `None` | Sets the name of a file containing a list of trusted SSL Certificate Authorities. |
|
||||
/// | `statement-cache-capacity` | `100` | The maximum number of prepared statements stored in the cache. Set to `0` to disable. |
|
||||
/// | `host` | `None` | Path to the directory containing a PostgreSQL unix domain socket, which will be used instead of TCP if set. |
|
||||
/// | `application-name` | `None` | The name will be displayed in the pg_stat_activity view and included in CSV log entries. |
|
||||
/// | `user` | result of `whoami` | PostgreSQL user name to connect as. |
|
||||
/// | `password` | `None` | Password to be used if the server demands password authentication. |
|
||||
/// | `port` | `5432` | Port number to connect to at the server host, or socket file name extension for Unix-domain connections. |
|
||||
/// | `dbname` | `None` | The database name. |
|
||||
///
|
||||
/// The URI scheme designator can be either `postgresql://` or `postgres://`.
|
||||
/// Each of the URI parts is optional.
|
||||
@ -37,6 +42,7 @@ pub use ssl_mode::PgSslMode;
|
||||
/// postgresql://localhost/mydb
|
||||
/// postgresql://user@localhost
|
||||
/// postgresql://user:secret@localhost
|
||||
/// postgresql://localhost?dbname=mydb&user=postgres&password=postgres
|
||||
/// ```
|
||||
///
|
||||
/// # Example
|
||||
|
||||
@ -69,6 +69,16 @@ impl FromStr for PgConnectOptions {
|
||||
options = options.application_name(&*value);
|
||||
}
|
||||
|
||||
"port" => {
|
||||
options = options.port(value.parse().map_err(Error::config)?);
|
||||
}
|
||||
|
||||
"dbname" => options = options.database(&*value),
|
||||
|
||||
"user" => options = options.username(&*value),
|
||||
|
||||
"password" => options = options.password(&*value),
|
||||
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user