-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Open
Labels
Description
What version of Bun is running?
1.3.4+5eb2145b3
What platform is your computer?
Darwin 24.6.0 arm64 arm
What steps can reproduce the bug?
When using bun:sqlite, calling Database.prepare with a single binding value (for example, a string) does not bind the value and results in NULL being used instead. Passing the bindings as an array works as expected. This behavior seems inconsistent with the TypeScript definition of prepare, which allows ParamsType extends SQLQueryBindings | SQLQueryBindings[].
Code to reproduce
import { test } from "bun:test";
import { Database } from "bun:sqlite";
test("sqlite stmt", () => {
const db = new Database(":memory:", { strict: true });
const stmtCreate = db.prepare(
"CREATE TABLE IF NOT EXISTS test (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)",
);
stmtCreate.run();
// Case 1: single string binding (does NOT bind correctly)
const stmt1 = db.prepare("INSERT INTO test (name) VALUES (?)", "test1");
console.log(stmt1.toString());
// Actual: INSERT INTO test (name) VALUES (NULL)
// Expected: INSERT INTO test (name) VALUES ('test1')
// Case 2: array binding (works as expected)
const stmt2 = db.prepare("INSERT INTO test (name) VALUES (?)", ["test2"]);
console.log(stmt2.toString());
// INSERT INTO test (name) VALUES ('test2')
});What is the expected behavior?
Both of these calls should bind the parameter and produce SQL equivalent to:
INSERT INTO test (name) VALUES ('test1');
INSERT INTO test (name) VALUES ('test2');What do you see instead?
No response
Additional information
No response
coderabbitai