ADR 0016 — Keep Bun.SQL as the PostgreSQL driver
Status: accepted. Date: 2026-12-03.
Context
The framework runs on Bun.SQL (ADR 0002). Choosing a driver by preference or performance expectation is not enough: keeping it required proof of compatibility, features, stability and performance against postgres.js.
Decision
Keep Bun.SQL. The access layer stays behind @fellowframework/core (sql, query, transaction, afterCommit,
dbHealth, closeDb), so the driver remains replaceable without touching modules.
Evidence (evaluation suite run on Bun 1.4.4 and PostgreSQL 16 with no Node.js process; the suite is not shipped)
- Compatibility and features (30/30 checks):
- Types round-trip: unicode text, bigint above 2^53 (returned as a string), exact numeric, jsonb, text[] with commas and quotes, timestamptz with milliseconds, bytea, boolean, null.
- Row-level security through transaction-local
set_config: isolation without WHERE, no rows without a tenant, cross-tenant write rejected (42501). - 200 concurrent tenant transactions on a pool of 4: each sees its own tenant; nothing leaks into later pooled queries. A negative control (session-level setting) proves the probe detects a leak.
- Rollback on throw, savepoints, SQLSTATE on errors (23505, 42601, 57014),
unsafe()with bound$1parameters,set local statement_timeout, cached statements survivingALTER TABLE, pool recovery afterpg_terminate_backend(negative control: backends were actually killed).
- Stability (soak test): 24 workers of mixed transactions, savepoint failures and leak probes, with every pooled backend killed every 5 s. 30 s run: 125 549 operations, 0 tenant leaks, 0 unexpected errors (23 connection errors caused by 30 kills), 15 MB RSS growth, pool usable afterwards.
- Performance (same process, same pool of 4, best of 3, against postgres.js 3): Bun.SQL was ahead in every run on simple queries (≈1.6–2.7×), tenant transactions (≈1.4–1.7×) and reading 100k rows (≈2–3×). Local loopback only; this is a baseline, not a production benchmark.
- Core suite:
packages/core/tests/db.test.tsandtenancy.test.tscover transactions, context and row-level security.
Consequences
- Minimum Bun is 1.4.4. Bun 1.4.4 reworked Bun.SQL and fixed serious defects present before it (transactions
inside
Promise.allfalling back to autocommit after a ROLLBACK, arelease()race, the pool not growing back after lost connections, leaked server-side prepared statements, a no-opcancel()); see the Bun 1.4.4 release notes.fellow doctorenforces this minimum. - No migration work. postgres.js is not a dependency of the framework (it was only used for the comparison).
- Errors carry SQLSTATE in
errno(PostgresError), not incodeas postgres.js does. Code that maps database errors must readerrno. - Connection drops surface as errors to the in-flight query (the pool reconnects); callers that need retries must implement them explicitly.
Conditions for reassessment
- A Bun release regresses any of the checks above (run
bun test packageson every Bun upgrade). - A required feature is missing or broken in Bun.SQL: COPY, LISTEN/NOTIFY under load (
sql.listenexists but is not covered by the evaluation), or a pooler in transaction mode (PgBouncer) breaking transaction-localset_config. None is used today. - Production measurements contradict the local baseline.