PgTempDBBuilder

Struct PgTempDBBuilder 

Source
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: bool

Do 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

Source

pub fn new() -> PgTempDBBuilder

Create a new PgTempDBBuilder

Source

pub fn from_connection_uri(conn_uri: &str) -> Self

Parses the parameters out of a PostgreSQL connection URI and inserts them into the builder.

Source

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.

Source

pub async fn start_async(self) -> PgTempDB

Convenience function for calling spawn_blocking(self.start())

Source

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.

Source

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.

Source

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).

Source

pub fn with_bin_path(self, path: impl AsRef<Path>) -> Self

Set the directory that contains binaries like initdb, createdb, and postgres.

Source

pub fn with_username(self, username: &str) -> Self

Set the user name

Source

pub fn with_password(self, password: &str) -> Self

Set the user password

Source

pub fn with_port(self, port: u16) -> Self

Set the port

Source

pub fn with_dbname(self, dbname: &str) -> Self

Set the database name

Source

pub fn persist_data(self, persist: bool) -> Self

If set, the postgres data directory will not be deleted when the PgTempDB is dropped.

Source

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.

Source

pub fn load_database(self, path: &Path) -> Self

If set, the database will be loaded via psql from the given script on startup.

Source

pub fn get_user(&self) -> String

Get user if set or return default

Source

pub fn get_password(&self) -> String

Get password if set or return default

Source

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.

Source

pub fn get_dbname(&self) -> String

Get dbname if set or return default

Trait Implementations§

Source§

impl Clone for PgTempDBBuilder

Source§

fn clone(&self) -> PgTempDBBuilder

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PgTempDBBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for PgTempDBBuilder

Source§

fn default() -> PgTempDBBuilder

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.