Skip to content

fix: open the learning database through bun:sqlite when node:sqlite is missing - #137

Merged
DevMortimer merged 3 commits into
mainfrom
fix/bun-sqlite
Sep 29, 2026
Merged

DevMortimer merged 3 commits into
mainfrom
fix/bun-sqlite

Conversation

@DevMortimer

Copy link
Copy Markdown
Owner

Pi's release binaries are Bun --compile executables. In them import("node:sqlite") fails with No such built-in module: node:sqlite, so holds.db never opened and learning features were off for everyone running a release binary.

Change

  • node:sqlite stays the first choice, and its path is unchanged.
  • Only when that import fails and the process runs on Bun, src/sqlite-adapter.ts opens the database through bun:sqlite, wrapped to the DatabaseSync subset learning uses: get() turns Bun's null miss into undefined, exec()'s result object is dropped, and positional ? parameters pass through unchanged.
  • With neither module available, learning stays off behind one warning that names both modules.
  • A local type declaration for bun:sqlite keeps the build free of new dependencies.
  • Version bump to 0.74.1.

Verification

  • npm run check: 1197 pass / 0 fail on main, 1207 pass / 0 fail on this branch; typecheck and build clean.
  • npm run test:bun (Bun 1.4.2): 40 pass / 0 fail, including the unchanged learning tests against real bun:sqlite.
  • A Bun bundle of learning.ts with import("node:sqlite") forced to fail opened the database through bun:sqlite, wrote and read a hold, created the parent directory, and ran in WAL mode.
  • A Node child with node:sqlite blocked emits one warning naming both modules and falls back to the no-op handle.

…s missing

Pi's release binaries are Bun --compile executables, where import("node:sqlite")
fails with "No such built-in module: node:sqlite", so holds.db never opened and
learning was off for everyone running a release binary.

node:sqlite stays the first choice and its path is unchanged. Only when that
import fails and the process runs on Bun does src/sqlite-adapter.ts open the
file through bun:sqlite, wrapped to the DatabaseSync subset learning uses: get()
turns Bun's null miss into undefined, exec()'s result object is dropped, and
positional ? parameters pass through (learning binds no named keys, so the
$name prefixes never meet). With neither module loading, learning still turns
off behind one warning, which now names both modules.

tests/sqlite-adapter.test.ts runs everywhere against a fake with Bun's measured
shape and, under Bun (npm run test:bun), against real bun:sqlite together with
the learning tests. tests/learning-driver.test.ts runs two children on Node: one
proves the Node path still picks node:sqlite, the other blocks node:sqlite and
proves the single both-modules warning and the NOOP handle.
Bun's `create` option creates the file when it is missing; it defaults to
true, so the old comment described the opposite of what the flag does.
@DevMortimer
DevMortimer merged commit 0f11867 into main Sep 29, 2026
6 checks passed
@DevMortimer
DevMortimer deleted the fix/bun-sqlite branch September 29, 2026 00:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant