temp_postgres/lib.rs
1//! Easy temporary postgresql instance for unit tests.
2//!
3//! Use the [`TempPostgres`] struct to get a [`tokio_postgres::Client`] that is connected to a temporary postgres instance.
4//! All state of the spawned postgres instance is stored in a temporary directory, which will be cleaned up automatically (unless disabled).
5//!
6//! On Unix platforms, the client is connected over a Unix socket.
7//! Windows support is planned by picking a free TCP port on the loopback adapter.
8//!
9//! # Example
10//!
11//! See the [example in the repository](https://github.com/rocsys/temp-postgres/blob/main/examples/example.rs) for a more detailed example using [`assert2`](https://crates.io/crates/assert2).
12//! ```
13//! # #[tokio::main]
14//! # async fn main() -> Result<(), Box<dyn std::error::Error>> {
15//! use temp_postgres::TempPostgres;
16//!
17//! let postgres = TempPostgres::new().await?;
18//! println!("Using temporary directory: {}", postgres.directory().display());
19//!
20//! let client = postgres.client().await?;
21//! client.execute("CREATE TABLE pets (name TEXT PRIMARY KEY, species TEXT)", &[]).await?;
22//! # Ok(())
23//! # }
24
25#![warn(missing_docs)]
26
27mod error;
28mod temp_postgres;
29mod util;
30
31pub use error::Error;
32pub use temp_postgres::TempPostgres;
33pub use temp_postgres::TempPostgresBuilder;