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
| Variable | Description | Default |
|---|---|---|
PG_HOST | PostgreSQL host | 127.0.0.1 |
PG_PORT | PostgreSQL port | 5432 |
PG_USERNAME | Database username | (none) |
PG_PASSWORD | Database password | (none) |
PG_DATABASE | Database name | (none) |
PG_ROOT_USERNAME | Admin username | (none) |
PG_ROOT_PASSWORD | Admin password | (none) |
PG_ROOT_DATABASE | Admin database | (none) |
PG_MAX_CONNECTIONS | Max pool connections | 32 |
PG_MIN_CONNECTIONS | Min pool connections | 0 |
Structs§
- DB
- PostgreSQL database connection wrapper.
- DbConfig
- PostgreSQL configuration. PostgreSQL connection configuration.
Functions§
- ensure
- Ensure database and user exist, creating them if necessary.