Run a Postgresql database locally on Linux, MacOS or Windows as part of another Rust application or test.
[dependencies]
pg-embed = "0.2"
zip = "0.5.11"
A postgresql instance can be created using
PgEmbed::new(PgSettings, FetchSettings)
```rust use pgembed::postgres::{PgEmbed, PgSettings}; use pgembed::fetch; use pgembed::fetch::{OperationSystem, Architecture, FetchSettings, PGV13}; let pgsettings = PgSettings{ /// where to store the postgres executables executablesdir: "data/postgres".tostring(), /// where to store the database databasedir: "data/db".tostring(), port: 5432, user: "postgres".tostring(), password: "password".tostring(), /// clean up files and directories on drop persistent: false, starttimeout: Duration::fromsecs(15), }; let fetchsettings = FetchSettings{ host: "https://repo1.maven.org".tostring(), operatingsystem: OperationSystem::Darwin, architecture: Architecture::Amd64, version: PGV13 }; let mut pgemb = PgEmbed::new(pgsettings, fetchsettings);
/// async block only to show that these methods need to be executed in an async context async { /// Download, unpack, create password file and database pg_emb.setup().await;
/// start postgresql database
pg_emb.start_db().await;
}; /// stop postgresql database pgemb.stopdb(); ```
Reliant on the great work being done by zonkyio/embedded-postgres-binaries in order to fetch precompiled binaries from Maven.
pg-embed is licensed under the MIT license. Please read the LICENSE-MIT file in this repository for more information.
pg-embed follows semantic versioning, so breaking changes should only happen upon major version bumps. The only exception to this rule is breaking changes that happen due to implementation that was deemed to be a bug, security concerns, or it can be reasonably proved to affect no code. For the full details, see CHANGELOG.md.