Skip to content

Commit

Permalink
Release v0.2.1
Browse files Browse the repository at this point in the history
Just contains some documentation fixes
  • Loading branch information
boustrophedon committed Feb 27, 2024
1 parent 7a8d2e2 commit 608b6bc
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 26 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pgtemp"
version = "0.2.0"
version = "0.2.1"
edition = "2021"
authors = ["Harry Stern <harry@harrystern.net>",]
description = "Start local postgres servers for testing without Docker"
Expand Down
12 changes: 8 additions & 4 deletions src/daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@ pub mod cli {
use std::path::PathBuf;

#[derive(Parser, Debug)]
#[command(author, version, about)]
#[command(author, version)]
/// pgtemp allows you to spawn temporary postgresql databases for testing.
/// You provide a connection URI and pgtemp will listen on the given port and proxy each
/// connection to a new temporary database.
/// When the connection is disconnected, the database is cleaned up.
pub struct PgTempDaemonArgs {
#[arg(long)]
/// Single mode makes every connection go to the same database
/// Single mode makes every connection go to the same database, rather than starting a new
/// one per connection.
pub single: bool,

#[arg(long, value_name = "DIR")]
Expand All @@ -29,7 +33,7 @@ pub mod cli {
pub load_from: Option<PathBuf>,

/// The postgres connection uri to be used by pgtemp clients.
/// E.g. postgres://localhost:5432/mytestdb
/// E.g. postgresql://localhost:5432/mytestdb
pub connection_uri: String,
}
}
Expand Down Expand Up @@ -93,7 +97,7 @@ impl PgTempDaemon {
daemon
}

/// Add a new pre-initialized PgTempDB
/// Pre-initialize a [`PgTempDB`]
pub async fn allocate_db(&mut self) {
let mut builder = self.builder.clone();
// Reset the port so that a port is allocated randomly when we make
Expand Down
32 changes: 12 additions & 20 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ pub use daemon::*;

// temp db handle - actual db spawning code is in run_db mod

/// A struct representing a handle to a local PostgreSQL database that is currently running. Upon
/// drop or calling `shutdown`, the database is shut down and the directory its data is stored in
/// is deleted.
/// A struct representing a handle to a local PostgreSQL server that is currently running. Upon
/// drop or calling `shutdown`, the server is shut down and the directory its data is stored in
/// is deleted. See builder struct [`PgTempDBBuilder`] for options and settings.
pub struct PgTempDB {
dbuser: String,
dbpass: String,
Expand Down Expand Up @@ -89,7 +89,7 @@ impl PgTempDB {
}

/// Use [pg_dump](https://www.postgresql.org/docs/current/backup-dump.html) to dump the
/// database to the provided path.
/// database to the provided path upon drop or [`Self::shutdown`].
pub fn dump_database(&self, path: impl AsRef<Path>) {
let path_str = path.as_ref().to_str().unwrap();

Expand Down Expand Up @@ -280,24 +280,17 @@ impl Drop for PgTempDB {
// db config builder functions

/// Builder struct for PgTempDB.
///
/// Defaults:
/// temp dir prefix: `std::env::temp_dir()`, inside which `pgtemp-<random>/pg_data_dir` is created.
/// db_user: `postgres`
/// password: `password`
/// port: `<random unused port>` set when `PgTempDBBuilder::start` is called.
/// dbname: `postgres` - created by initdb default
#[derive(Debug, Clone)]
pub struct PgTempDBBuilder {
/// The directory in which to store the temporary PostgreSQL data directory
/// The directory in which to store the temporary PostgreSQL data directory.
pub temp_dir_prefix: Option<PathBuf>,
/// The cluster superuser created with `initdb`
/// The cluster superuser created with `initdb`. Default: `postgres`
pub db_user: Option<String>,
/// The password for the cluster superuser
/// The password for the cluster superuser. Default: `password`
pub password: Option<String>,
/// The port the server should run on.
/// The port the server should run on. Default: random unused port.
pub port: Option<u16>,
/// The name of the database to create on startup
/// The name of the database to create on startup. Default: `postgres`.
pub dbname: Option<String>,
/// Do not delete the data dir when the `PgTempDB` is dropped.
pub persist_data_dir: bool,
Expand Down Expand Up @@ -430,22 +423,21 @@ impl PgTempDBBuilder {
}

/// If set, the postgres data directory will not be deleted when the `PgTempDB` is dropped.
/// Note that if you are going to use this feature, make sure to disconnect all clients before
/// dropping the database.
#[must_use]
pub fn persist_data(mut self, persist: bool) -> Self {
self.persist_data_dir = persist;
self
}

/// If set, the database will be dumped via the `pg_dump` utility to the given location.
/// If set, the database will be dumped via the `pg_dump` utility to the given location on drop
/// or upon calling [`PgTempDB::shutdown`].
#[must_use]
pub fn dump_database(mut self, path: &Path) -> Self {
self.dump_path = Some(path.into());
self
}

/// If set, the database will be loaded via `psql` from the given script.
/// If set, the database will be loaded via `psql` from the given script on startup.
#[must_use]
pub fn load_database(mut self, path: &Path) -> Self {
self.load_path = Some(path.into());
Expand Down

0 comments on commit 608b6bc

Please sign in to comment.