pg-embed
Run a Postgresql database locally on Linux, MacOS or Windows as part of another Rust application or test.
The currently supported async runtime for pg-embed is tokio.
Support for async-std and actix is planned and will be available soon.
Usage
-
Add pg-embed to your Cargo.toml
Library without sqlx migration support
# Cargo.toml [] = { = "0.5", = false, = ["rt_tokio"] }
Library with sqlx migration support
# Cargo.toml [] = "0.5"
A postgresql instance can be created using PgEmbed::new(PgSettings, PgFetchSettings)
Examples
use ;
use fetch;
use ;
use Duration;
use PathBuf;
/// Postgresql settings
let pg_settings = PgSettings;
/// Postgresql binaries download settings
let fetch_settings = PgFetchSettings;
/// async block only to show that these methods need to be executed in an async context
async ;
// get the base postgresql uri
// `postgres://{username}:{password}@localhost:{port}`
let pg_uri: &str = &pg.db_uri;
// get a postgresql database uri
// `postgres://{username}:{password}@localhost:{port}/{specified_database_name}`
let pg_db_uri: String = pg.full_db_uri;
Recent Breaking Changes
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.
License
pg-embed is licensed under the MIT license. Please read the LICENSE-MIT file in this repository for more information.
Notes
Reliant on the great work being done by zonkyio/embedded-postgres-binaries in order to fetch precompiled binaries from Maven.