Crates.io | temp-postgres |
lib.rs | temp-postgres |
version | 0.1.0 |
source | src |
created_at | 2024-03-07 10:42:49.85917 |
updated_at | 2024-03-07 10:42:49.85917 |
description | temporary postgres instance meant for unit tests |
homepage | |
repository | https://github.com/rocsys/temp-postgres |
max_upload_size | |
id | 1165823 |
size | 52,498 |
Easy temporary postgresql instance for unit tests.
Use the [TempPostgres
] struct to get a [tokio_postgres::Client
] that is connected to a temporary postgres instance.
All state of the spawned postgres instance is stored in a temporary directory, which will be cleaned up automatically (unless disabled).
On Unix platforms, the client is connected over a Unix socket. Windows support is planned by picking a free TCP port on the loopback adapter.
See the example in the repository for a more detailed example using assert2
.
use temp_postgres::TempPostgres;
let postgres = TempPostgres::new().await?;
println!("Using temporary directory: {}", postgres.directory().display());
let client = postgres.client().await?;
client.execute("CREATE TABLE pets (name TEXT PRIMARY KEY, species TEXT)", &[]).await?;
License: MIT