pg-embed

Crates.io Docs.rs Crates.io Crates.io

Run a Postgresql database locally on Linux, MacOS or Windows as part of another Rust application or test.

Usage

Import following packages:

pg-embed = "0.1"

zip = "0.5.11"

A postgresql instance can be created using
PgEmbed::new(PgSettings, FetchSettings)

Examples

```rust use pgembed::postgres::{PgEmbed, PgSettings}; use pgembed::fetch; use pgembed::fetch::{OperationSystem, Architecture, FetchSettings, PGV13}; let pgsettings = PgSettings{ executablesdir: "data/postgres".tostring(), databasedir: "data/db".tostring(), user: "postgres".tostring(), password: "password".tostring(), persistent: false }; 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 { /// download postgresql pgemb.aquirepostgres().await;

/// create database password file
pg_emb.create_password_file().await;

/// initialize postgresql database
pg_emb.init_db().await;

/// start postgresql database
pg_emb.start_db().await;

/// stop postgresql database
pg_emb.stop_db().await;

} ```

Notes

Reliant on the great work being done by zonkyio/embedded-postgres-binaries in order to fetch precompiled binaries from Maven.