feat(pgdb): add DATABASE_URI environment variable support

Add support for PostgreSQL connection URIs via DATABASE_URI env var.
When set, it takes precedence over config files and PoolOptions are
ignored (pool settings can be specified in URI query string).
This commit is contained in:
2025-11-29 11:52:45 -08:00
parent 7291f00f48
commit 283d3936f6
3 changed files with 125 additions and 16 deletions

View File

@@ -93,8 +93,34 @@ sslmode: prefer
## Environment Variables
- `DATABASE_URI` - PostgreSQL connection URI (takes precedence over config files)
- `DATABASE_CONFIG_FILE` - Override config file location
### URI Format
Standard PostgreSQL URI format:
```
postgresql://user:password@host:port/database?sslmode=require&pool_max_conns=10
```
Pool settings can be included in the URI query string:
- `pool_max_conns`, `pool_min_conns`
- `pool_max_conn_lifetime`, `pool_max_conn_idle_time`
- `pool_health_check_period`
When using `DATABASE_URI`, `PoolOptions` are ignored and all settings come from the URI.
Example with CloudNativePG:
```yaml
# Mount the secret's 'uri' key as DATABASE_URI
env:
- name: DATABASE_URI
valueFrom:
secretKeyRef:
name: mydb-app
key: uri
```
## When to Use
**Use `pgdb.OpenPool()`** (this package) when: