pub struct Config { /* private fields */ }
Implementations§
Source§impl Config
impl Config
Sourcepub fn user(&mut self, user: &str) -> &mut Config
pub fn user(&mut self, user: &str) -> &mut Config
Sets the user to authenticate with.
Required.
Sourcepub fn get_user(&self) -> Option<&str>
pub fn get_user(&self) -> Option<&str>
Gets the user to authenticate with, if one has been configured with
the user
method.
Sourcepub fn password<T>(&mut self, password: T) -> &mut Config
pub fn password<T>(&mut self, password: T) -> &mut Config
Sets the password to authenticate with.
Sourcepub fn get_password(&self) -> Option<&[u8]>
pub fn get_password(&self) -> Option<&[u8]>
Gets the password to authenticate with, if one has been configured with
the password
method.
Sourcepub fn dbname(&mut self, dbname: &str) -> &mut Config
pub fn dbname(&mut self, dbname: &str) -> &mut Config
Sets the name of the database to connect to.
Defaults to the user.
Sourcepub fn get_dbname(&self) -> Option<&str>
pub fn get_dbname(&self) -> Option<&str>
Gets the name of the database to connect to, if one has been configured
with the dbname
method.
Sourcepub fn options(&mut self, options: &str) -> &mut Config
pub fn options(&mut self, options: &str) -> &mut Config
Sets command line options used to configure the server.
Sourcepub fn get_options(&self) -> Option<&str>
pub fn get_options(&self) -> Option<&str>
Gets the command line options used to configure the server, if the
options have been set with the options
method.
Sourcepub fn application_name(&mut self, application_name: &str) -> &mut Config
pub fn application_name(&mut self, application_name: &str) -> &mut Config
Sets the value of the application_name
runtime parameter.
Sourcepub fn get_application_name(&self) -> Option<&str>
pub fn get_application_name(&self) -> Option<&str>
Gets the value of the application_name
runtime parameter, if it has
been set with the application_name
method.
Sourcepub fn ssl_mode(&mut self, ssl_mode: SslMode) -> &mut Config
pub fn ssl_mode(&mut self, ssl_mode: SslMode) -> &mut Config
Sets the SSL configuration.
Defaults to prefer
.
Sourcepub fn get_ssl_mode(&self) -> SslMode
pub fn get_ssl_mode(&self) -> SslMode
Gets the SSL configuration.
Sourcepub fn ssl_negotiation(
&mut self,
ssl_negotiation: SslNegotiation,
) -> &mut Config
pub fn ssl_negotiation( &mut self, ssl_negotiation: SslNegotiation, ) -> &mut Config
Sets the SSL negotiation method.
Defaults to postgres
.
Sourcepub fn get_ssl_negotiation(&self) -> SslNegotiation
pub fn get_ssl_negotiation(&self) -> SslNegotiation
Gets the SSL negotiation method.
pub fn host(&mut self, host: &str) -> &mut Config
Sourcepub fn host_path<T>(&mut self, host: T) -> &mut Config
pub fn host_path<T>(&mut self, host: T) -> &mut Config
Adds a Unix socket host to the configuration.
Unlike host
, this method allows non-UTF8 paths.
Sourcepub fn get_hosts(&self) -> &[Host]
pub fn get_hosts(&self) -> &[Host]
Gets the hosts that have been added to the configuration with host
.
Sourcepub fn port(&mut self, port: u16) -> &mut Config
pub fn port(&mut self, port: u16) -> &mut Config
Adds a port to the configuration.
Multiple ports can be specified by calling this method multiple times. There must either be no ports, in which case the default of 5432 is used, a single port, in which it is used for all hosts, or the same number of ports as hosts.
Sourcepub fn get_ports(&self) -> &[u16]
pub fn get_ports(&self) -> &[u16]
Gets the ports that have been added to the configuration with port
.
Sourcepub fn target_session_attrs(
&mut self,
target_session_attrs: TargetSessionAttrs,
) -> &mut Config
pub fn target_session_attrs( &mut self, target_session_attrs: TargetSessionAttrs, ) -> &mut Config
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-only
secondary servers. Defaults to Any
.
Sourcepub fn get_target_session_attrs(&self) -> TargetSessionAttrs
pub fn get_target_session_attrs(&self) -> TargetSessionAttrs
Gets the requirements of the session.
Sourcepub fn tls_server_end_point(
&mut self,
tls_server_end_point: impl AsRef<[u8]>,
) -> &mut Self
pub fn tls_server_end_point( &mut self, tls_server_end_point: impl AsRef<[u8]>, ) -> &mut Self
change the remote peer’s tls certificates. it’s often coupled with Postgres::connect_io
API for manual tls
session connecting and channel binding authentication.
§Examples
use xitca_postgres::{Config, Postgres};
// handle tls connection on your own.
async fn connect_io() {
let mut cfg = Config::try_from("postgres://postgres:postgres@localhost/postgres").unwrap();
// an imaginary function where you establish a tls connection to database on your own.
// the established connection should be providing valid cert bytes.
let (io, certs) = your_tls_connector().await;
// set cert bytes to configuration
cfg.tls_server_end_point(certs);
// give xitca-postgres the config and established io and finish db session process.
let _ = Postgres::new(cfg).connect_io(io).await;
}
async fn your_tls_connector() -> (MyTlsStream, Vec<u8>) {
todo!("your tls connecting logic lives here. the process can be async or not.")
}
// a possible type representation of your manual tls connection to database
struct MyTlsStream;