Basic Structure
database
Specifies the PostgreSQL driver to use. Type:"pg" | "pgnative" (optional)
Default: "pg"
pg vs pgnative
-
"pg": PostgreSQL driver implemented in pure JavaScript (recommended)- Install:
pnpm add pg - Cross-platform support
- Sufficient performance for most cases
- Install:
-
"pgnative": Native driver using C bindings- Install:
pnpm add pg-native - Faster performance (especially for large data processing)
- Requires compilation, platform-dependent
- Install:
name
Specifies the database name. Type:string (required)
defaultOptions
Database settings that apply to all environments. Uses Knex configuration options. Type:DatabaseConfig (required)
connection Settings
Sets database connection information.Additional Knex Options
You can set various Knex options besides connection:environments
Specifies different database settings for each environment. OverridesdefaultOptions.
Type: (optional)
Environment-Specific Configuration Example
Determining Current Environment
Sonamu determines the current environment in this order:NODE_ENVenvironment variable- Default:
development
Slave DB Configuration
When using read-only replicas (slave):Slave DB is used for read-only queries to distribute load from the master DB.
Practical Examples
Basic Local Development Setup
Using Environment Variables (Recommended)
Multi-Environment Configuration
Docker Compose Environment
Connection Testing
To verify your database settings are correct:Important Notes
1. Password Security
2. Port Number Type
3. Connection Pool Size
Next Steps
After completing database settings:- server - Server options and plugin settings
- database/migrations - Manage schema with migrations
- troubleshooting - Connection problem troubleshooting