Skip to main content

Crate qm_pg

Crate qm_pg 

Source
Expand description

PostgreSQL connection and utilities.

This crate provides PostgreSQL connection management with automatic database and user creation, connection pooling, and SeaORM integration.

§Features

  • Connection Management: Connect to PostgreSQL with connection pooling
  • Auto-provisioning: Create databases and users if they don’t exist
  • SeaORM Integration: Convert pools to SeaORM database connections
  • Configuration: Environment-based configuration with prefix support

§Usage

```ignore use qm_pg::{DbConfig, DB};

#[tokio::main] async fn main() -> anyhow::Result<()> { let config = DbConfig::new()?; let db = DB::new(“my-app”, &config).await?; let conn = db.database_connection(); Ok(()) } ```

§Environment Variables

VariableDescriptionDefault
PG_HOSTPostgreSQL host127.0.0.1
PG_PORTPostgreSQL port5432
PG_USERNAMEDatabase username(none)
PG_PASSWORDDatabase password(none)
PG_DATABASEDatabase name(none)
PG_ROOT_USERNAMEAdmin username(none)
PG_ROOT_PASSWORDAdmin password(none)
PG_ROOT_DATABASEAdmin database(none)
PG_MAX_CONNECTIONSMax pool connections32
PG_MIN_CONNECTIONSMin pool connections0

Structs§

DB
PostgreSQL database connection wrapper.
DbConfig
PostgreSQL configuration. PostgreSQL connection configuration.

Functions§

ensure
Ensure database and user exist, creating them if necessary.