[−][src]Struct sqlx::postgres::PgConnectOptions
postgres
only.Options and flags which can be used to configure a PostgreSQL connection.
A value of PgConnectOptions
can be parsed from a connection URI,
as described by libpq.
The general form for a connection URI is:
postgresql://[user[:password]@][host][:port][/dbname][?param1=value1&...]
Parameters
Parameter | Default | Description |
---|---|---|
sslmode | prefer | Determines whether or with what priority a secure SSL TCP/IP connection will be negotiated. See PgSqlSslMode . |
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. |
The URI scheme designator can be either postgresql://
or postgres://
.
Each of the URI parts is optional.
postgresql://
postgresql://localhost
postgresql://localhost:5433
postgresql://localhost/mydb
postgresql://user@localhost
postgresql://user:secret@localhost
Example
// URI connection string let conn = PgConnection::connect("postgres://localhost/mydb").await?; // Manually-constructed options let conn = PgConnectOptions::new() .host("secret-host") .port(2525) .username("secret-user") .password("secret-password") .ssl_mode(PgSslMode::Require) .connect().await?;
Implementations
impl PgConnectOptions
[src]
pub fn new() -> PgConnectOptions
[src]
postgres
only.Creates a new, default set of options ready for configuration.
By default, this reads the following environment variables and sets their equivalent options.
PGHOST
PGPORT
PGUSER
PGPASSWORD
PGDATABASE
PGSSLROOTCERT
PGSSLMODE
Example
let options = PgConnectOptions::new();
pub fn host(self, host: &str) -> PgConnectOptions
[src]
postgres
only.Sets the name of the host to connect to.
If a host name begins with a slash, it specifies Unix-domain communication rather than TCP/IP communication; the value is the name of the directory in which the socket file is stored.
The default behavior when host is not specified, or is empty, is to connect to a Unix-domain socket
Example
let options = PgConnectOptions::new() .host("localhost");
pub fn port(self, port: u16) -> PgConnectOptions
[src]
postgres
only.Sets the port to connect to at the server host.
The default port for PostgreSQL is 5432
.
Example
let options = PgConnectOptions::new() .port(5432);
pub fn socket(self, path: impl AsRef<Path>) -> PgConnectOptions
[src]
postgres
only.Sets a custom path to a directory containing a unix domain socket, switching the connection method from TCP to the corresponding socket.
By default set to None
.
pub fn username(self, username: &str) -> PgConnectOptions
[src]
postgres
only.Sets the username to connect as.
Defaults to be the same as the operating system name of the user running the application.
Example
let options = PgConnectOptions::new() .username("postgres");
pub fn password(self, password: &str) -> PgConnectOptions
[src]
postgres
only.Sets the password to use if the server demands password authentication.
Example
let options = PgConnectOptions::new() .username("root") .password("safe-and-secure");
pub fn database(self, database: &str) -> PgConnectOptions
[src]
postgres
only.Sets the database name. Defaults to be the same as the user name.
Example
let options = PgConnectOptions::new() .database("postgres");
pub fn ssl_mode(self, mode: PgSslMode) -> PgConnectOptions
[src]
postgres
only.Sets whether or with what priority a secure SSL TCP/IP connection will be negotiated with the server.
By default, the SSL mode is Prefer
, and the client will
first attempt an SSL connection but fallback to a non-SSL connection on failure.
Ignored for Unix domain socket communication.
Example
let options = PgConnectOptions::new() .ssl_mode(PgSslMode::Require);
pub fn ssl_root_cert(self, cert: impl AsRef<Path>) -> PgConnectOptions
[src]
postgres
only.Sets the name of a file containing SSL certificate authority (CA) certificate(s). If the file exists, the server's certificate will be verified to be signed by one of these authorities.
Example
let options = PgConnectOptions::new() // Providing a CA certificate with less than VerifyCa is pointless .ssl_mode(PgSslMode::VerifyCa) .ssl_root_cert("./ca-certificate.crt");
pub fn statement_cache_capacity(self, capacity: usize) -> PgConnectOptions
[src]
postgres
only.Sets the capacity of the connection's statement cache in a number of stored distinct statements. Caching is handled using LRU, meaning when the amount of queries hits the defined limit, the oldest statement will get dropped.
The default cache capacity is 100 statements.
Trait Implementations
impl Clone for PgConnectOptions
[src]
fn clone(&self) -> PgConnectOptions
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl ConnectOptions for PgConnectOptions
[src]
type Connection = PgConnection
fn connect(
&self
) -> Pin<Box<dyn Future<Output = Result<<PgConnectOptions as ConnectOptions>::Connection, Error>> + Send>> where
<PgConnectOptions as ConnectOptions>::Connection: Sized,
[src]
&self
) -> Pin<Box<dyn Future<Output = Result<<PgConnectOptions as ConnectOptions>::Connection, Error>> + Send>> where
<PgConnectOptions as ConnectOptions>::Connection: Sized,
impl Debug for PgConnectOptions
[src]
impl Default for PgConnectOptions
[src]
fn default() -> PgConnectOptions
[src]
impl FromStr for PgConnectOptions
[src]
Auto Trait Implementations
impl RefUnwindSafe for PgConnectOptions
impl Send for PgConnectOptions
impl Sync for PgConnectOptions
impl Unpin for PgConnectOptions
impl UnwindSafe for PgConnectOptions
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,