pub struct PostgresConnectionString { /* private fields */ }
Expand description
Struct representing a PostgreSQL
connection string
Implementations§
Source§impl PostgresConnectionString
impl PostgresConnectionString
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new and empty PostgresConnectionString
This function initializes a new PostgresConnectionString
with empty values.
Without any further changes this results in the string postgres://
which isn’t really useful.
This function can be chained other functions to fill the missing fields in the connection string.
§Examples
use connection_string_generator::postgres::PostgresConnectionString;
PostgresConnectionString::new()
.set_username_and_password("user", "password")
.set_host_with_port("localhost", 5432)
.set_database_name("db_name")
.set_connect_timeout(30);
Sourcepub fn set_username_without_password(self, username: &str) -> Self
pub fn set_username_without_password(self, username: &str) -> Self
Sets/Replaces the username and omits the password in the connection string
§Examples
use connection_string_generator::postgres::PostgresConnectionString;
PostgresConnectionString::new().set_username_without_password("user");
Sourcepub fn set_username_and_password(self, username: &str, password: &str) -> Self
pub fn set_username_and_password(self, username: &str, password: &str) -> Self
Sets/Replaces the username and the password
§Examples
use connection_string_generator::postgres::PostgresConnectionString;
PostgresConnectionString::new().set_username_and_password("user", "password");
Sourcepub fn set_host_with_default_port(self, host: &str) -> Self
pub fn set_host_with_default_port(self, host: &str) -> Self
Sets/Replaces the host and omits the port in the connection string (this usually results in the usage of the default port)
§Examples
use connection_string_generator::postgres::PostgresConnectionString;
PostgresConnectionString::new().set_host_with_default_port("localhost");
Sourcepub fn set_host_with_port(self, host: &str, port: usize) -> Self
pub fn set_host_with_port(self, host: &str, port: usize) -> Self
Sets/Replaces the host and the port
§Examples
use connection_string_generator::postgres::PostgresConnectionString;
PostgresConnectionString::new().set_host_with_port("localhost", 5432);
Sourcepub fn set_database_name(self, db_name: &str) -> Self
pub fn set_database_name(self, db_name: &str) -> Self
Sets/Replaces the database name
§Examples
use connection_string_generator::postgres::PostgresConnectionString;
PostgresConnectionString::new().set_database_name("db_name");
Sourcepub fn set_connect_timeout(self, timeout: usize) -> Self
pub fn set_connect_timeout(self, timeout: usize) -> Self
Sets/Replaces the connect timeout in seconds
§Examples
use connection_string_generator::postgres::PostgresConnectionString;
PostgresConnectionString::new().set_connect_timeout(30);
Sourcepub fn dangerously_set_parameter(self, key: &str, value: &str) -> Self
pub fn dangerously_set_parameter(self, key: &str, value: &str) -> Self
Sets/replaces ANY parameter even if it doesn’t exist in the list of allowed/implemented parameters
§Examples
use connection_string_generator::postgres::PostgresConnectionString;
PostgresConnectionString::new().dangerously_set_parameter("parameter", "value");