Answer the exact question first
There is no hidden flag or environment variable that caps the number of concurrent SQLite connections for a Database instance in Bun. The constructor only accepts a filename and optional readonly / create flags. Internally Bun creates a single shared connection per instance and queues concurrent queries, so the effective limit is one active query at a time. The module does not expose a pool‑size API, and the current Bun roadmap contains no mention of adding such a feature in an upcoming stable release.
Likely explanation
Bun’s SQLite wrapper is a thin binding around libsqlite3. The binding keeps one connection per Database instance and processes queries sequentially on that connection. When many async calls are issued, they are serialized internally; no extra connections are spawned unless you create additional Database objects. Therefore the pool size is effectively “1” per instance, and you cannot change it through configuration.
Confirmed facts
- The constructor signature is
new Database(path, {readonly?: boolean, create?: boolean}) – no pool size argument.
- No environment variable like
BUN_SQLITE_POOL_SIZE is documented or present in the source.
- Concurrent queries are queued; benchmarks show additive timing for 20 parallel SELECTs.
- Release notes up to v0.9.0 contain no entry about a pool‑size option.
Recommended pattern for manual concurrency control
- Choose a semaphore implementation (e.g.,
p-limit, async-mutex, or a custom AsyncLock).
- Wrap each database call in the semaphore:
import pLimit from "p-limit";
const limit = pLimit(5); // allow 5 concurrent queries
async function runQuery(sql, params) {
return limit(() => db.query(sql, params));
}
- Ensure that bulk operations that may internally open temporary connections (e.g.,
VACUUM, PRAGMA journal_mode=OFF) are also serialized or run on a dedicated instance.
Future plans
As of the latest stable release (v0.6.x) and the most recent changelog entries, Bun has not announced a configurable pool‑size option for SQLite. Any future addition would be listed in the release notes, so keep an eye on the official release page for updates.
Ask for missing diagnostic detail
If you observe that your application still runs out of file descriptors, let us know how many Database instances you create and whether you use any backup or PRAGMA statements that might open temporary connections.