Skip to content
Open
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
d28f020
Provide a better-sqlite3 module backed by bun:sqlite
robobun Aug 1, 2026
0657c5f
[autofix.ci] apply automated fixes
autofix-ci[bot] Aug 1, 2026
443ee5b
Tighten comments in better-sqlite3 shim
robobun Aug 1, 2026
c7ef033
Collapse module header to a single line
robobun Aug 1, 2026
3e0e897
Address review: fix .raw().iterate() with duplicate column names
robobun Aug 1, 2026
d59c653
Address coderabbit review: id-0 match, verbose, unsafeMode, tests
robobun Aug 1, 2026
d39ce9f
Open bun:sqlite with strict: true so named params match better-sqlite3
robobun Aug 1, 2026
47a0b30
Drop dead state and collapse all()/get()/iterate() to one mapRow path
robobun Aug 1, 2026
a8367b8
declaredTypes: drop the hasExecuted guard; tidy hasInstance and crash…
robobun Aug 1, 2026
340368c
Lazy-require node:util for inspect; use bun.com docs URL
robobun Aug 1, 2026
bae77a9
iterate(): validate bound parameters at call time, not on first next()
robobun Aug 1, 2026
69396d3
exec(): no-op on empty/comment-only input; update declaredTypes docs
robobun Aug 1, 2026
f50d995
Refuse read methods on non-reader statements; trace expanded SQL
robobun Aug 1, 2026
f2cc60b
Trace in finally so failing statements are still logged; cache column…
robobun Aug 1, 2026
ca2f612
Guard the verbose callback; snapshot TypedArrays in .bind()
robobun Aug 1, 2026
166cc71
bind(): narrow snapshot guard to Uint8Array (Buffer.from is element-w…
robobun Aug 1, 2026
01dc6c8
ci: retrigger
robobun Aug 1, 2026
8fb5753
close() finalizes outstanding prepared statements
robobun Aug 1, 2026
6cf828f
Track prepared statements via WeakRef so GC can reclaim them before c…
robobun Aug 1, 2026
0ae892b
Prune dead WeakRefs from the statements Set via FinalizationRegistry
robobun Aug 2, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/runtime/sqlite.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ class Statement<ReturnType, ParamsType> {

columnNames: string[]; // the column names of the result set
columnTypes: string[]; // types based on actual values in first row (call .get()/.all() first)
declaredTypes: (string | null)[]; // types from CREATE TABLE schema (call .get()/.all() first)
declaredTypes: (string | null)[]; // types from CREATE TABLE schema
paramsCount: number; // the number of parameters expected by the statement
native: any; // the native object representing the statement

Expand Down
7 changes: 2 additions & 5 deletions packages/bun-types/sqlite.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -829,25 +829,22 @@ declare module "bun:sqlite" {
* - The exact type string declared in the `CREATE TABLE` statement
* - `null` for columns without declared types, such as expressions and computed columns
*
* The statement must be executed at least once before accessing this
* property. Available for both read-only and read-write statements.
* Available immediately after `prepare()`; the statement does not need to
* be executed first. Available for both read-only and read-write statements.
*
* @example
* ```ts
* // For table columns:
* const stmt = db.prepare("SELECT id, name, weight FROM products");
* stmt.get();
* console.log(stmt.declaredTypes);
* // => ["INTEGER", "TEXT", "REAL"]
*
* // For expressions (no declared types):
* const exprStmt = db.prepare("SELECT length('bun') AS str_length");
* exprStmt.get();
* console.log(exprStmt.declaredTypes);
* // => [null]
* ```
*
* @throws Error if statement hasn't been executed
* @since Bun v1.2.13
*/
readonly declaredTypes: Array<string | null>;
Expand Down
2 changes: 1 addition & 1 deletion scripts/handle-crash-patterns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ else if (
closeAction = {
reason: "not_planned",
comment: `Duplicate of #4290.
better-sqlite3 is not supported yet in Bun due to missing V8 C++ APIs. For now, you can try [bun:sqlite](https://bun.com/docs/api/sqlite) for an almost drop-in replacement.`,
Bun cannot load the better-sqlite3 native addon because it uses V8 C++ APIs that Bun does not implement. In current Bun releases \`require("better-sqlite3")\` resolves to a built-in module backed by [bun:sqlite](https://bun.com/docs/api/sqlite); please upgrade Bun and use \`require("better-sqlite3")\` directly instead of loading the \`.node\` file.`,
};
}

Expand Down
4 changes: 2 additions & 2 deletions src/codegen/internal-module-registry-scanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function createInternalModuleRegistry(basedir: string) {
for (let i = 0; i < moduleList.length; i++) {
const prefix = moduleList[i].startsWith("node/")
? "node:"
: moduleList[i].startsWith("bun:")
: moduleList[i].startsWith("bun/")
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Comment thread
claude[bot] marked this conversation as resolved.
? "bun:"
: moduleList[i].startsWith("internal/")
? "internal/"
Expand Down Expand Up @@ -64,7 +64,7 @@ export function createInternalModuleRegistry(basedir: string) {

const requireTransformer = (specifier: string, from: string) => {
const directMatch = internalRegistry.get(specifier);
if (directMatch) return codegenRequireId(`${directMatch}/*${specifier}*/`);
if (directMatch !== undefined) return codegenRequireId(`${directMatch}/*${specifier}*/`);

const relativeMatch =
resolveSyncOrNull(specifier, path.join(basedir, path.dirname(from))) ?? resolveSyncOrNull(specifier, basedir);
Expand Down
1 change: 0 additions & 1 deletion src/install/default-trusted-dependencies.txt
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ azure-functions-core-tools
azure-streamanalytics-cicd
backport
bcrypt
better-sqlite3
bigint-buffer
blake-hash
bs-platform
Expand Down
3 changes: 2 additions & 1 deletion src/js/bun/sqlite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ interface CppSQLStatement {
paramsCount: number;
columnTypes: string[];
declaredTypes: (string | null)[];
readonly: boolean;
safeIntegers: boolean;
}

Expand Down Expand Up @@ -614,7 +615,7 @@ class Database implements SqliteTypes.Database {
exclusive: {
value: wrapTransaction(fn, db, controller.exclusive),
},
database: { value: this, enumerable: true },
database: { value: self ?? this, enumerable: true },
};

defineProperties(properties.default.value, properties);
Expand Down
Loading
Loading