pub struct PgTempDB { /* private fields */ }Expand description
A struct representing a handle to a local PostgreSQL server that is currently running. Upon
drop or calling shutdown, the server is shut down and the directory its data is stored in
is deleted. See builder struct PgTempDBBuilder for options and settings.
Implementations§
Source§impl PgTempDB
impl PgTempDB
Sourcepub fn from_builder(builder: PgTempDBBuilder) -> PgTempDB
pub fn from_builder(builder: PgTempDBBuilder) -> PgTempDB
Start a PgTempDB with the parameters configured from a PgTempDBBuilder
Sourcepub fn builder() -> PgTempDBBuilder
pub fn builder() -> PgTempDBBuilder
Creates a builder that can be used to configure the details of the temporary PostgreSQL server
Sourcepub fn new() -> PgTempDB
pub fn new() -> PgTempDB
Creates a new PgTempDB with default configuration and starts a PostgreSQL server.
Sourcepub async fn async_new() -> PgTempDB
pub async fn async_new() -> PgTempDB
Creates a new PgTempDB with default configuration and starts a PostgreSQL server in an async context.
Sourcepub fn dump_database(&self, path: impl AsRef<Path>)
pub fn dump_database(&self, path: impl AsRef<Path>)
Use pg_dump to dump the
database to the provided path upon drop or Self::shutdown.
Sourcepub fn load_database(&self, path: impl AsRef<Path>)
pub fn load_database(&self, path: impl AsRef<Path>)
Use psql to load the database from the provided dump file. See Self::dump_database.
Sourcepub fn shutdown(self)
pub fn shutdown(self)
Send a signal to the database to shutdown the server, then wait for the process to exit. Equivalent to calling drop on this struct.
We send SIGINT to the postgres process to initiate a fast shutdown (https://www.postgresql.org/docs/current/server-shutdown.html), which causes all transactions to be aborted and connections to be terminated.
NOTE: This is currently a blocking function. It sends SIGINT to the postgres server, waits for the process to exit, and also does IO to remove the temp directory.
Sourcepub fn data_dir(&self) -> PathBuf
pub fn data_dir(&self) -> PathBuf
Returns the path to the data directory being used by this databaset.
Sourcepub fn db_user(&self) -> &str
pub fn db_user(&self) -> &str
Returns the database username used when connecting to the postgres server.
Sourcepub fn db_pass(&self) -> &str
pub fn db_pass(&self) -> &str
Returns the database password used when connecting to the postgres server.
Sourcepub fn connection_string(&self) -> String
pub fn connection_string(&self) -> String
Returns a connection string that can be passed to a libpq connection function.
Example output:
host=localhost port=15432 user=pgtemp password=pgtemppw-9485 dbname=pgtempdb-324
Sourcepub fn connection_uri(&self) -> String
pub fn connection_uri(&self) -> String
Returns a generic connection URI that can be passed to most SQL libraries’ connect methods.
Example output:
postgresql://pgtemp:pgtemppw-9485@localhost:15432/pgtempdb-324