pub struct PgTempDBBuilder {
pub temp_dir_prefix: Option<PathBuf>,
pub db_user: Option<String>,
pub password: Option<String>,
pub port: Option<u16>,
pub dbname: Option<String>,
pub persist_data_dir: bool,
pub dump_path: Option<PathBuf>,
pub load_path: Option<PathBuf>,
pub server_configs: HashMap<String, String>,
pub initdb_args: HashMap<String, String>,
pub bin_path: Option<PathBuf>,
}Expand description
Builder struct for PgTempDB.
Fields§
§temp_dir_prefix: Option<PathBuf>The directory in which to store the temporary PostgreSQL data directory.
db_user: Option<String>The cluster superuser created with initdb. Default: postgres
password: Option<String>The password for the cluster superuser. Default: password
port: Option<u16>The port the server should run on. Default: random unused port.
dbname: Option<String>The name of the database to create on startup. Default: postgres.
persist_data_dir: boolDo not delete the data dir when the PgTempDB is dropped.
dump_path: Option<PathBuf>The path to dump the database to (via pg_dump) when the PgTempDB is dropped.
load_path: Option<PathBuf>The path to load the database from (via psql) when the PgTempDB is started.
server_configs: HashMap<String, String>Other server configuration data to be set in postgresql.conf via initdb -c
initdb_args: HashMap<String, String>Direct arguments to pass to the initdb binary (e.g. –encoding=UTF8), distinct from postgres configs (-c)
bin_path: Option<PathBuf>Prefix PostgreSQL binary names (initdb, createdb, and postgres) with this path, instead of searching $PATH
Implementations§
Source§impl PgTempDBBuilder
impl PgTempDBBuilder
Sourcepub fn new() -> PgTempDBBuilder
pub fn new() -> PgTempDBBuilder
Create a new PgTempDBBuilder
Sourcepub fn from_connection_uri(conn_uri: &str) -> Self
pub fn from_connection_uri(conn_uri: &str) -> Self
Parses the parameters out of a PostgreSQL connection URI and inserts them into the builder.
Sourcepub fn start(self) -> PgTempDB
pub fn start(self) -> PgTempDB
Creates the temporary data directory and starts the PostgreSQL server with the configured parameters.
If the current user is root, will attempt to run the initdb and postgres commands as
the postgres user.
Sourcepub async fn start_async(self) -> PgTempDB
pub async fn start_async(self) -> PgTempDB
Convenience function for calling spawn_blocking(self.start())
Sourcepub fn with_data_dir_prefix(self, prefix: impl AsRef<Path>) -> Self
pub fn with_data_dir_prefix(self, prefix: impl AsRef<Path>) -> Self
Set the directory in which to put the (temporary) PostgreSQL data directory. This is not the data directory itself: a new temporary directory is created inside this one.
Sourcepub fn with_config_param(self, key: &str, value: &str) -> Self
pub fn with_config_param(self, key: &str, value: &str) -> Self
Set an arbitrary PostgreSQL server configuration parameter that will passed to the postgresql process at runtime.
Sourcepub fn with_initdb_arg(self, key: &str, value: &str) -> Self
pub fn with_initdb_arg(self, key: &str, value: &str) -> Self
Set an arbitrary argument that will be passed directly to the initdb binary during database initialization. These are direct arguments like –encoding or –locale, not configuration parameters that get written to postgresql.conf (use with_config_param for those).
Sourcepub fn with_bin_path(self, path: impl AsRef<Path>) -> Self
pub fn with_bin_path(self, path: impl AsRef<Path>) -> Self
Set the directory that contains binaries like initdb, createdb, and postgres.
Sourcepub fn with_username(self, username: &str) -> Self
pub fn with_username(self, username: &str) -> Self
Set the user name
Sourcepub fn with_password(self, password: &str) -> Self
pub fn with_password(self, password: &str) -> Self
Set the user password
Sourcepub fn with_dbname(self, dbname: &str) -> Self
pub fn with_dbname(self, dbname: &str) -> Self
Set the database name
Sourcepub fn persist_data(self, persist: bool) -> Self
pub fn persist_data(self, persist: bool) -> Self
If set, the postgres data directory will not be deleted when the PgTempDB is dropped.
Sourcepub fn dump_database(self, path: &Path) -> Self
pub fn dump_database(self, path: &Path) -> Self
If set, the database will be dumped via the pg_dump utility to the given location on drop
or upon calling PgTempDB::shutdown.
Sourcepub fn load_database(self, path: &Path) -> Self
pub fn load_database(self, path: &Path) -> Self
If set, the database will be loaded via psql from the given script on startup.
Sourcepub fn get_password(&self) -> String
pub fn get_password(&self) -> String
Get password if set or return default
Sourcepub fn get_port_or_set_random(&mut self) -> u16
pub fn get_port_or_set_random(&mut self) -> u16
Unlike the other getters, this getter will try to open a new socket to find an unused port, and then set it as the current port.
Sourcepub fn get_dbname(&self) -> String
pub fn get_dbname(&self) -> String
Get dbname if set or return default
Trait Implementations§
Source§impl Clone for PgTempDBBuilder
impl Clone for PgTempDBBuilder
Source§fn clone(&self) -> PgTempDBBuilder
fn clone(&self) -> PgTempDBBuilder
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more