Added MySQL-specific environment variables with proper precedence:
**New MySQL Environment Variables:**
- `MYSQL_HOST` (defaults to `localhost`)
- `MYSQL_PORT` (defaults to `3306`)
- `MYSQL_USER` (with fallback to `$USER`)
- `MYSQL_PASSWORD` (defaults to empty)
- `MYSQL_DATABASE` (defaults to `mysql`)
- `MYSQL_URL` (primary connection URL)
- `TLS_MYSQL_DATABASE_URL` (SSL/TLS connection URL)
**Enhanced TLS Support:**
- Added `TLS_MYSQL_DATABASE_URL` for MySQL TLS connections
- Enhanced `TLS_DATABASE_URL` to work with MySQL protocol detection
- All TLS URLs automatically enable SSL mode
**Environment Variable Precedence:**
- MySQL-specific env vars (e.g., `$MYSQL_USER`) override generic ones (e.g., `$USER`)
- Environment variable names override URL protocols for semantic intent
- Proper URL precedence: `MYSQL_URL` > `DATABASE_URL` > `TLS_MYSQL_DATABASE_URL` > `TLS_DATABASE_URL`
**Comprehensive Testing:**
- 23 adapter precedence tests covering all MySQL env vars
- Tests for TLS URL handling and protocol detection
- Tests for env var name precedence over protocols
- All existing tests (241 total) continue to pass
This brings MySQL environment variable support in line with PostgreSQL,
providing a complete and intuitive configuration experience.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
Fixed logic where PGURL="mysql://" would incorrectly return mysql adapter instead of postgres.
Environment variable names now take semantic precedence over URL protocols:
- MYSQL_URL=postgres://host → mysql adapter (name wins)
- PGURL=mysql://host → postgres adapter (name wins)
- DATABASE_URL=mysql://host → mysql adapter (protocol detection as fallback)
This is more intuitive and matches user expectations - if you set PGURL, you clearly
intend PostgreSQL regardless of what protocol might be in the URL value.
Simplified logic:
1. Explicit adapter (highest priority)
2. Environment variable name (semantic intent)
3. Protocol detection (fallback for DATABASE_URL only)
4. Default to postgres
Added comprehensive tests to verify environment variable names override protocols
in all scenarios. All 236 existing tests continue to pass.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
Fixed bug where MYSQL_URL=root@localhost:3306/test would incorrectly be treated
as postgres instead of mysql due to missing protocol detection.
Now properly infers adapter from environment variable names:
- MYSQL_URL → mysql adapter (even without mysql:// protocol)
- POSTGRES_URL, PGURL, PG_URL → postgres adapter (even without postgres:// protocol)
- Protocol detection still takes precedence when present
- Maintains proper precedence order across environment variables
Added comprehensive tests to verify:
- MYSQL_URL without protocol correctly infers mysql
- POSTGRES_URL without protocol correctly infers postgres
- All existing functionality continues to work
This ensures that environment variable names provide semantic hints about
the intended database adapter even when URLs lack explicit protocols.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
Added tests to verify MySQL port defaulting behavior:
- MySQL URL without port defaults to 3306
- Explicit MySQL adapter defaults to 3306
- Both URL and explicit adapter scenarios work correctly
This documents the expected behavior and ensures proper port
handling across all MySQL connection scenarios.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
The previous implementation incorrectly checked if MYSQL_URL was a SQLite URL
using parseDefinitelySqliteUrl(). This fix properly checks the protocol of
environment URLs to determine the correct adapter:
- mysql://, mariadb://, mysqls:// → mysql adapter
- postgres://, postgresql:// → postgres adapter
- SQLite URLs (detected by parseDefinitelySqliteUrl) → sqlite adapter
Added tests to verify MYSQL_URL and POSTGRES_URL environment variables
correctly infer their respective adapters and that precedence is respected.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
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>
### What does this PR do?
handle Int24 to be numbers
### How did you verify your code works?
tests
---------
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
### What does this PR do?
add `lastInsertRowid` (matching SQLite)
add `affectedRows`
fix `mysql_native_password` deprecated authentication
fix AuthSwitch
Fixes:
https://github.com/oven-sh/bun/issues/22178#issuecomment-3228716080
### How did you verify your code works?
tests
---------
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
### What does this PR do?
Fix handling BIT(1) and BIT(N) on binary protocol and text protocol, now
behavior is consistent
### How did you verify your code works?
Tests
### What does this PR do?
Change tinyint/bool type from mysql to number instead of bool to match
mariadb and mysql2 behavior since tinyint/bool can be bigger than 1 in
mysql
Fixes https://github.com/oven-sh/bun/issues/22158
### How did you verify your code works?
Test
---------
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
### What does this PR do?
Support the following:
```javascript
const nom = await sql`SELECT name FROM food WHERE category IN ${sql(['bun', 'baozi', 'xiaolongbao'])}`;
```
Previously, only e.g., `sql([1, 2, 3])` was supported.
To be honest I'm not sure what the semantics of SQLHelper *ought* to be.
I'm pretty sure objects ought to be auto-inferred. I'm not sure about
arrays, but given the rest of the code in `SQLHelper` trying to read the
tea leaves on stringified numeric keys I figured someone cared about
this use case. I don't know about other types, but I'm pretty sure that
`Object.keys("bun") === [0, 1, 2]` is an oversight and unintended.
(Incidentally, the reason numbers previously worked is because
`Object.keys(4) === []`). I decided that all non-objects and non-arrays
should be treated as not having auto-inferred columns.
Fixes#18637
### How did you verify your code works?
I wrote a test, but was unable to run it (or any other tests in this
file) locally due to Docker struggles. I sure hope it works!
### What does this PR do?
Fixes#20729
### How did you verify your code works?
There is a test
---------
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
### What does this PR do?
Add MySQL support, Refactor will be in a followup PR
### How did you verify your code works?
A lot of tests
---------
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: cirospaciari <6379399+cirospaciari@users.noreply.github.com>
### What does this PR do?
Support sqlite in the Bun.sql API
Fixes#18951Fixes#19701
### How did you verify your code works?
tests
---------
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
### What does this PR do?
We should not call .deinit() after .toJS otherwise hasPendingActivity
will access invalid memory
### How did you verify your code works?
Test run it with debug build on macos or asan on and will catch it
---------
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
### What does this PR do?
Fix: https://github.com/oven-sh/bun/issues/21351
Relevant changes:
Fix advance to properly cleanup success and failed queries that could be
still be in the queue
Always ref before executing
Use stronger atomics for ref/deref and hasPendingActivity
Fallback when thisValue is freed/null/zero and check if vm is being
shutdown
The bug in --hot in `resolveRopeIfNeeded` Issue is not meant to be fixed
in this PR this is a fix for the postgres regression
Added assertions so this bug is easier to catch on CI
### How did you verify your code works?
Test added
---------
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>