Internals: Bun notes
Verified notes on embedding assets in a compiled binary and on Drizzle adapters for Bun.
Findings from issue #12, checked with Bun 1.4.5 and drizzle-orm 0.45.4.
Embedding assets in a compiled binary
Import the file with the file import attribute. Bun bundles it into the executable, and the import resolves to a path in Bun’s virtual filesystem:
import page from "./page.html" with { type: "file" };
const html = await Bun.file(page).text();
console.log(Bun.embeddedFiles.map((f) => f.name));Compile with bun build --compile --target=bun-darwin-arm64 main.ts --outfile app.
Verified results:
- The import resolves to a path under
/$bunfs/root/, such as/$bunfs/root/page-1xq33tzy.html.Bun.file()reads it. Bun.embeddedFileslists every embedded file as aBlobwith anameandsize.- The compiled binary ran from an empty directory and read its embedded files. Nothing is read from disk.
- File names carry a content hash by default. Pass
--asset-naming="[name].[ext]"for stable names.
Sources: Bun.embeddedFiles reference and Bun bundler docs. The with { type: "file" } behavior above was checked by building and running a binary, not taken from a doc page.
Drizzle adapters
Both adapters ship in the pinned drizzle-orm 0.45.4. We confirmed the modules drizzle-orm/bun-sqlite and drizzle-orm/bun-sql exist in node_modules.
drizzle-orm/bun-sqlite | drizzle-orm/bun-sql | |
|---|---|---|
| Driver | bun:sqlite | Bun.sql (SQL from bun) |
| Dialect | SQLite | Postgres only |
| Database class | BunSQLiteDatabase, synchronous ('sync') | BunSQLDatabase, extends PgDatabase, asynchronous |
| Migrator | migrate in drizzle-orm/bun-sqlite/migrator | migrate in drizzle-orm/bun-sql/migrator |
| Transactions | Synchronous | client.begin, with savepoint for nested transactions |
Notes and gaps:
bun-sqliteis what Turntable uses today (packages/core/src/db/index.ts). Its sync API means a Postgres port changes call sites from sync to async, so repos should expose async signatures from the start.bun-sqlis Postgres-only in drizzle, even thoughBun.sqlalso speaks other databases.bun-sqlsends queries throughclient.unsafe(query, params). We have not load-tested it, and we have not verified behavior across Postgres versions or poolers.- Turntable applies its own embedded migrations through a dialect-agnostic runner, so neither drizzle migrator is needed at runtime.
Sources: Drizzle with Bun SQLite, Drizzle with Bun SQL, Bun SQL, and the type declarations in drizzle-orm/bun-sql and drizzle-orm/bun-sqlite.