37 releases

new 0.0.52 May 7, 2025
0.0.50 Mar 24, 2025
0.0.39 Nov 25, 2024
0.0.20 Jul 25, 2024
0.0.13 Mar 28, 2024

#1029 in Database interfaces

Download history 17/week @ 2025-01-17 150/week @ 2025-01-24 210/week @ 2025-01-31 169/week @ 2025-02-07 181/week @ 2025-02-14 222/week @ 2025-02-21 109/week @ 2025-02-28 26/week @ 2025-03-07 62/week @ 2025-03-14 167/week @ 2025-03-21 44/week @ 2025-03-28 198/week @ 2025-04-04 81/week @ 2025-04-11 19/week @ 2025-04-18 24/week @ 2025-04-25 80/week @ 2025-05-02

268 downloads per month
Used in 2 crates

MIT license

18KB
229 lines

Quick Microservices PostgreSQL - qm-pg

utilities to work with the PostgreSQL database


GitHub repositoryCargo packageDocs

github.com - quick-microservice-rs crates.io - qm-pg
github.com - workflow - build


Description

With this crate it is easy to get a PostgreSQL configuration with the most common settings.

Usage

let pgdb = qm::pg::DB::new("example", &qm::pg::DbConfig::new()?).await?;

The Config is populated with environment variables. By default, all variables with the prefix PG_ are considered.

The prefix can be changed by using a builder pattern.

let example_config = qm::pg::DbConfig::builder().with_prefix("EXAMPLE_").build()?;

Variables and Defaults

These variables are available and are set with the following defaults.

variable struct field default
PG_HOST host "127.0.0.1"
PG_PORT port 5432
PG_MAX_CONNECTIONS max_connections 32
PG_MIN_CONNECTIONS min_connections 0
PG_ACQUIRE_TIMEOUT acquire_timeout 30
PG_IDLE_TIMEOUT idle_timeout 10 * 60
PG_MAX_LIFETIME max_lifetime 30 * 60
PG_USERNAME username
PG_PASSWORD password
PG_DATABASE database
PG_ROOT_USERNAME root_username
PG_ROOT_PASSWORD root_password
PG_ROOT_DATABASE root_database
PG_SHARDED sharded false
address With credentials: postgresql://{username}:{password}@{host}:{port}/;
With username: postgresql://{username}@{host}:{port}/;
Without: postgresql://{host}:{port}/;
If provided, database will be appended
root_address With credentials: postgresql://{root_username}:{root_password}@{host}:{port}/;
With username: postgresql://{root_username}@{host}:{port}/;
Without: postgresql://{host}:{port}/;
If provided, root_database will be appended

Dependencies

~57MB
~1M SLoC