postgresfixture/lib.rs
1#![warn(clippy::pedantic)]
2#![allow(clippy::enum_glob_use)]
3#![allow(clippy::many_single_char_names)]
4#![allow(clippy::match_same_arms)]
5#![allow(clippy::missing_errors_doc)]
6#![allow(clippy::module_name_repetitions)]
7#![allow(clippy::must_use_candidate)]
8
9//!
10//! The essential functionality in this crate is in the `Cluster` struct and its
11//! implementation. This covers the logic you need to create, run, and destroy
12//! PostgreSQL clusters of any officially supported version (and a few older
13//! versions that are not supported upstream).
14//!
15//! ```rust
16//! use postgresfixture::prelude::*;
17//! for runtime in strategy::default().runtimes() {
18//! let data_dir = tempdir::TempDir::new("data")?;
19//! let cluster = Cluster::new(&data_dir, runtime)?;
20//! cluster.start()?;
21//! assert_eq!(cluster.databases()?, vec!["postgres", "template0", "template1"]);
22//! let mut conn = cluster.connect("template1")?;
23//! let rows = conn.query("SELECT 1234 -- …", &[])?;
24//! let collations: Vec<i32> = rows.iter().map(|row| row.get(0)).collect();
25//! assert_eq!(collations, vec![1234]);
26//! cluster.stop()?;
27//! }
28//! # Ok::<(), ClusterError>(())
29//! ```
30//!
31//! You may want to use this with the functions in the [`coordinate`] module
32//! like [`run_and_stop`][coordinate::run_and_stop] and
33//! [`run_and_destroy`][coordinate::run_and_destroy]. These add locking to the
34//! setup and teardown steps of using a cluster so that multiple processes can
35//! safely share a single on-demand cluster.
36//!
37
38#[macro_use]
39extern crate lazy_static;
40
41#[doc = include_str!("../README.md")]
42#[cfg(doctest)]
43pub struct README;
44
45pub mod cluster;
46pub mod coordinate;
47pub mod lock;
48pub mod prelude;
49pub mod runtime;
50pub mod version;
51
52mod util;