Lines 8-48javascript
8 * On macOS, Apple's system SQLite is compiled with SQLITE_OMIT_LOAD_EXTENSION,
9 * which prevents loading native extensions like sqlite-vec. When running under
10 * Bun we call Database.setCustomSQLite() to swap in Homebrew's full-featured
11 * SQLite build before creating any database instances.
13export const isBun = typeof globalThis.Bun !== "undefined";
14export const DEFAULT_SQLITE_BUSY_TIMEOUT_MS = 120_000;
15/** Resolve the per-connection SQLite busy timeout from the environment. */
16export function resolveSqliteBusyTimeout(value = process.env.QMD_SQLITE_BUSY_TIMEOUT) {
17 if (value === undefined || value.trim() === "")
18 return DEFAULT_SQLITE_BUSY_TIMEOUT_MS;
19 const parsed = Number(value);
20 if (!Number.isFinite(parsed) || parsed < 0)
21 return DEFAULT_SQLITE_BUSY_TIMEOUT_MS;
22 return Math.floor(parsed);
27 // Dynamic string prevents tsc from resolving bun:sqlite on Node.js builds
28 const bunSqlite = "bun:" + "sqlite";
29 const BunDatabase = (await import(/* @vite-ignore */ bunSqlite)).Database;
30 // See: https://bun.com/docs/runtime/sqlite#setcustomsqlite
MediumDynamic Require
Package source references dynamic require/import behavior.
dist/db.jsView on unpkg · L28 31 if (process.platform === "darwin") {
32 const homebrewPaths = [
33 "/opt/homebrew/opt/sqlite/lib/libsqlite3.dylib", // Apple Silicon
34 "/usr/local/opt/sqlite/lib/libsqlite3.dylib", // Intel
36 for (const p of homebrewPaths) {
38 BunDatabase.setCustomSQLite(p);
44 _Database = BunDatabase;
45 // setCustomSQLite may have silently failed — test that extensions actually work.
47 const { getLoadablePath } = await import("sqlite-vec");
48 const vecPath = getLoadablePath();