mirror of
https://github.com/oven-sh/bun
synced 2026-02-14 21:01:52 +00:00
This commit refactors Bun.SQL's options parsing to fix issue #22147 and properly separate PostgreSQL and MySQL environment variables based on the chosen adapter. Key changes: 1. Separate adapter detection from options parsing 2. Only read environment variables appropriate for the selected adapter 3. Respect proper precedence: explicit options > adapter-specific env vars > generic env vars 4. Add support for unix:// protocol with explicit adapter specification 5. Validate adapter-protocol compatibility Adapter detection logic: - If adapter is explicitly set: use it - If adapter is set to "mysql": use mysql adapter - If adapter is set to "postgres"/"postgresql": use postgres adapter - If protocol is mysql/mariadb/mysqls: use mysql adapter - If protocol is postgres/postgresql: use postgres adapter - If no protocol in URL: default to postgres adapter - For unix:// protocol: require explicit adapter Environment variable precedence by adapter: - PostgreSQL: Only reads PGHOST, PGUSER, PGPASSWORD, etc. + generic USER/USERNAME - MySQL: Only reads generic USER/USERNAME (no widely standardized MySQL env vars) - SQLite: Only reads DATABASE_URL for SQLite URLs This prevents mixing of PostgreSQL env vars when using MySQL adapter and vice versa, while ensuring explicit connection options always take precedence over environment variables. Fixes: #22147 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>