Master the built-in bun:sqlite driver and its key patterns.
0 / 5 completed
1 / 5
At standup, a dev wants a built-in SQLite driver in Bun with no npm install. Which import provides it?
Bun ships a native SQLite driver importable as bun:sqlite, requiring no external dependency. It exposes a synchronous, high-performance API. This is the idiomatic way to use SQLite inside a Bun runtime.
2 / 5
During a PR review, a dev opens a database file with bun:sqlite. Which class do they instantiate?
You open a database by constructing a Database instance, e.g. new Database('app.db'). It represents the open connection and exposes query methods. Passing :memory: creates an in-memory database for tests.
3 / 5
In a design review, the team runs the same insert many times with different values. Which method should they reuse?
Calling db.prepare(sql) compiles a reusable prepared statement that you run with bound parameters. Reusing it avoids recompiling the SQL and prevents injection via parameter binding. This is the correct pattern for repeated queries.
4 / 5
An incident report shows partial writes after a crash mid-batch. Which bun:sqlite feature ensures all-or-nothing?
Wrapping inserts in a transaction via db.transaction(fn) makes the batch atomic, committing all or rolling back on error. This prevents partial writes when a crash interrupts a batch. Transactions also dramatically speed up bulk inserts.
5 / 5
During a code review, a dev enables a journaling mode for better concurrent reads. Which mode is recommended?
Enabling WAL mode via PRAGMA journal_mode = WAL allows concurrent readers while a writer is active. It generally improves write throughput and read concurrency. This is a common tuning step for SQLite under load.