pub struct Config { /* fields omitted */ }
Connection configuration.
Configuration can be parsed from libpq-style connection strings. These strings come in two formats:
This format consists of space-separated key-value pairs. Values which are either the empty string or containwhitespace should be wrapped in'
.'
and\
characters should be backslash-escaped.
user
- The username to authenticate with. Required.password
- The password to authenticate with.dbname
- The name of the database to connect to. Defaults to the username.options
- Command line options used to configure the server.application_name
- Sets theapplication_name
parameter on the server.sslmode
- Controls usage of TLS. If set todisable
, TLS will not be used. If set toprefer
, TLS will be usedif available, but not used otherwise. If set torequire
, TLS will be forced to be used. Defaults toprefer
.host
- The host to connect to. On Unix platforms, if the host starts with a/
character it is treated as thepath to the directory containing Unix domain sockets. Otherwise, it is treated as a hostname. Multiple hostscan be specified, separated by commas. Each host will be tried in turn when connecting. Required if connectingwith theconnect
method.port
- The port to connect to. Multiple ports can be specified, separated by commas. The number of ports must beeither 1, in which case it will be used for all hosts, or the same as the number of hosts. Defaults to 5432 ifomitted or the empty string.connect_timeout
- The time limit in seconds applied to each socket-level connection attempt. Note that hostnamescan resolve to multiple IP addresses, and this limit is applied to each address. Defaults to no timeout.keepalives
- Controls the use of TCP keepalive. A value of 0 disables keepalive and nonzero integers enable it.This option is ignored when connecting with Unix sockets. Defaults to on.keepalives_idle
- The number of seconds of inactivity after which a keepalive message is sent to the server.This option is ignored when connecting with Unix sockets. Defaults to 2 hours.target_session_attrs
- Specifies requirements of the session. If set toread-write
, the client will check thatthetransaction_read_write
session parameter is set toon
. This can be used to connect to the primary serverin a database cluster as opposed to the secondary read-only mirrors. Defaults toall
.host=localhost user=postgres connect_timeout=10 keepalives=0
host=/var/lib/postgresql,localhost port=1234 user=postgres password='password with spaces'
host=host1,host2,host3 port=1234,,5678 user=postgres target_session_attrs=read-write
This format resembles a URL with a scheme of eitherpostgres://
orpostgresql://
. All components are optional,and the format accept query parameters for all of the key-value pairs described in the section above. Multiplehost/port pairs can be comma-separated. Unix socket paths in the host section of the URL should be percent-encoded,as the path component of the URL specifies the database name.
postgresql://user@localhost
postgresql://user:password@%2Fvar%2Flib%2Fpostgresql/mydb?connect_timeout=10
postgresql://user@host1:1234,host2,host3:5678?target_session_attrs=read-write
postgresql:///mydb?user=user&host=/var/lib/postgresql
implConfig
[src]pub fnnew() ->Config
[src]Creates a new configuration.
pub fnuser(&mut self, user: &str) -> &mutConfig
[src]Sets the user to authenticate with.
Required.
pub fnget_user(&self) ->Option<&str>
[src]Gets the user to authenticate with, if one has been configured withtheuser
method.
pub fnpassword<T>(&mut self, password: T) -> &mutConfigwhere
T:AsRef<[u8]>,
[src]Sets the password to authenticate with.
pub fnget_password(&self) ->Option<&[u8]>
[src]Gets the password to authenticate with, if one has been configured withthepassword
method.
pub fndbname(&mut self, dbname: &str) -> &mutConfig
[src]Sets the name of the database to connect to.
Defaults to the user.
pub fnget_dbname(&self) ->Option<&str>
[src]Gets the name of the database to connect to, if one has been configuredwith thedbname
method.
pub fnoptions(&mut self, options: &str) -> &mutConfig
[src]Sets command line options used to configure the server.
pub fnget_options(&self) ->Option<&str>
[src]Gets the command line options used to configure the server, if theoptions have been set with theoptions
method.
pub fnapplication_name(&mut self, application_name: &str) -> &mutConfig
[src]Sets the value of theapplication_name
runtime parameter.
pub fnget_application_name(&self) ->Option<&str>
[src]Gets the value of theapplication_name
runtime parameter, if it hasbeen set with theapplication_name
method.
pub fnssl_mode(&mut self, ssl_mode:SslMode) -> &mutConfig
[src]Sets the SSL configuration.
Defaults toprefer
.
pub fnget_ssl_mode(&self) ->SslMode
[src]Gets the SSL configuration.
pub fnhost(&mut self, host: &str) -> &mutConfig
[src]Adds a host to the configuration.
Multiple hosts can be specified by calling this method multiple times, and each will be tried in order. On Unixsystems, a host starting with a/
is interpreted as a path to a directory containing Unix domain sockets.
pub fnget_hosts(&self) ->&[Host]
[src]Gets the hosts that have been added to the configuration withhost
.
pub fnhost_path<T>(&mut self, host: T) -> &mutConfigwhere
T:AsRef<Path>,
[src]Adds a Unix socket host to the configuration.
Unlikehost
, this method allows non-UTF8 paths.
pub fnport(&mut self, port:u16) -> &mutConfig
[src]Adds a port to the configuration.
Multiple ports can be specified by calling this method multiple times. There must either be no ports, in whichcase the default of 5432 is used, a single port, in which it is used for all hosts, or the same number of portsas hosts.
pub fnget_ports(&self) ->&[u16]
[src]Gets the ports that have been added to the configuration withport
.
pub fnconnect_timeout(&mut self, connect_timeout:Duration) -> &mutConfig
[src]Sets the timeout applied to socket-level connection attempts.
Note that hostnames can resolve to multiple IP addresses, and this timeout will apply to each address of eachhost separately. Defaults to no limit.
pub fnget_connect_timeout(&self) ->Option<&Duration>
[src]Gets the connection timeout, if one has been set with theconnect_timeout
method.
pub fnkeepalives(&mut self, keepalives:bool) -> &mutConfig
[src]Controls the use of TCP keepalive.
This is ignored for Unix domain socket connections. Defaults totrue
.
pub fnget_keepalives(&self) ->bool
[src]Reports whether TCP keepalives will be used.
pub fnkeepalives_idle(&mut self, keepalives_idle:Duration) -> &mutConfig
[src]Sets the amount of idle time before a keepalive packet is sent on the connection.
This is ignored for Unix domain sockets, or if thekeepalives
option is disabled. Defaults to 2 hours.
pub fnget_keepalives_idle(&self) ->Duration
[src]Gets the configured amount of idle time before a keepalive packet willbe sent on the connection.
pub fntarget_session_attrs(
&mut self,
target_session_attrs:TargetSessionAttrs
) -> &mutConfig
[src]Sets the requirements of the session.
This can be used to connect to the primary server in a clustered database rather than one of the read-onlysecondary servers. Defaults toAny
.
pub fnget_target_session_attrs(&self) ->TargetSessionAttrs
[src]Gets the requirements of the session.
pub fnchannel_binding(
&mut self,
channel_binding:ChannelBinding
) -> &mutConfig
[src]Sets the channel binding behavior.
Defaults toprefer
.
pub fnget_channel_binding(&self) ->ChannelBinding
[src]Gets the channel binding behavior.
pub fnconnect<T>(&self, tls: T) ->Result<Client,Error>where
T:MakeTlsConnect<Socket> + 'static +Send,
T::TlsConnect:Send,
T::Stream:Send,
<T::TlsConnect asTlsConnect<Socket>>::Future:Send,
[src]Opens a connection to a PostgreSQL database.
implClone forConfig
[src]implDebug forConfig
[src]implDefault forConfig
[src]implFrom<Config> forConfig
[src]implFromStr forConfig
[src]implRefUnwindSafe forConfig
implSend forConfig
implSync forConfig
implUnpin forConfig
implUnwindSafe forConfig
impl<T>Any for Twhere
T: 'static + ?Sized,
[src]impl<T>Borrow<T> for Twhere
T: ?Sized,
[src]impl<T>BorrowMut<T> for Twhere
T: ?Sized,
[src]fnborrow_mut(&mut self) ->&mutT
[src]impl<T>From<T> for T
[src]impl<T, U>Into<U> for Twhere
U:From<T>,
[src]impl<T> Same<T> for T
typeOutput = T
Should always beSelf
impl<T>ToOwned for Twhere
T:Clone,
[src]typeOwned = T
The resulting type after obtaining ownership.
fnto_owned(&self) -> T
[src]fnclone_into(&self, target:&mutT)
[src]impl<T, U>TryFrom<U> for Twhere
U:Into<T>,
[src]typeError =Infallible
The type returned in the event of a conversion error.
fntry_from(value: U) ->Result<T, <T asTryFrom<U>>::Error>
[src]impl<T, U>TryInto<U> for Twhere
U:TryFrom<T>,
[src]typeError = <U asTryFrom<T>>::Error
The type returned in the event of a conversion error.
fntry_into(self) ->Result<U, <U asTryFrom<T>>::Error>
[src]impl<V, T> VZip<V> for Twhere
V: MultiLane<T>,
fnvzip(self) -> V