mirror of
https://github.com/oven-sh/bun
synced 2026-02-02 15:08:46 +00:00
fix(types): correct JSDoc examples for Statement.get() and Statement.all()
The examples incorrectly showed that calling these methods without parameters returns null/empty, but the actual behavior (and the prose documentation) states that the last bound values are used. Fixes #26622 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
10
packages/bun-types/sqlite.d.ts
vendored
10
packages/bun-types/sqlite.d.ts
vendored
@@ -610,11 +610,14 @@ declare module "bun:sqlite" {
|
|||||||
* ```ts
|
* ```ts
|
||||||
* const stmt = db.prepare("SELECT * FROM foo WHERE bar = ?");
|
* const stmt = db.prepare("SELECT * FROM foo WHERE bar = ?");
|
||||||
*
|
*
|
||||||
|
* stmt.all();
|
||||||
|
* // => [] (no previous bindings)
|
||||||
|
*
|
||||||
* stmt.all("baz");
|
* stmt.all("baz");
|
||||||
* // => [{bar: "baz"}]
|
* // => [{bar: "baz"}]
|
||||||
*
|
*
|
||||||
* stmt.all();
|
* stmt.all();
|
||||||
* // => []
|
* // => [{bar: "baz"}] (uses last bound value)
|
||||||
*
|
*
|
||||||
* stmt.all("foo");
|
* stmt.all("foo");
|
||||||
* // => [{bar: "foo"}]
|
* // => [{bar: "foo"}]
|
||||||
@@ -633,11 +636,14 @@ declare module "bun:sqlite" {
|
|||||||
* ```ts
|
* ```ts
|
||||||
* const stmt = db.prepare("SELECT * FROM foo WHERE bar = ?");
|
* const stmt = db.prepare("SELECT * FROM foo WHERE bar = ?");
|
||||||
*
|
*
|
||||||
|
* stmt.get();
|
||||||
|
* // => null (no previous bindings)
|
||||||
|
*
|
||||||
* stmt.get("baz");
|
* stmt.get("baz");
|
||||||
* // => {bar: "baz"}
|
* // => {bar: "baz"}
|
||||||
*
|
*
|
||||||
* stmt.get();
|
* stmt.get();
|
||||||
* // => null
|
* // => {bar: "baz"} (uses last bound value)
|
||||||
*
|
*
|
||||||
* stmt.get("foo");
|
* stmt.get("foo");
|
||||||
* // => {bar: "foo"}
|
* // => {bar: "foo"}
|
||||||
|
|||||||
54
test/regression/issue/26622.test.ts
Normal file
54
test/regression/issue/26622.test.ts
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
import { Database } from "bun:sqlite";
|
||||||
|
import { expect, test } from "bun:test";
|
||||||
|
|
||||||
|
// https://github.com/oven-sh/bun/issues/26622
|
||||||
|
// When parameters are omitted from .get(), .all(), etc., the statement should
|
||||||
|
// run with the last bound values (or no parameters if there are none)
|
||||||
|
|
||||||
|
test("Statement.get() uses last bound value when called without parameters", () => {
|
||||||
|
using db = new Database(":memory:");
|
||||||
|
db.run("CREATE TABLE foo (bar TEXT)");
|
||||||
|
db.run("INSERT INTO foo VALUES ('baz')");
|
||||||
|
db.run("INSERT INTO foo VALUES ('foo')");
|
||||||
|
|
||||||
|
using stmt = db.prepare("SELECT * FROM foo WHERE bar = ?");
|
||||||
|
|
||||||
|
// First call without binding returns null (no match with empty/no parameter)
|
||||||
|
expect(stmt.get()).toBe(null);
|
||||||
|
|
||||||
|
// Bind and get a value
|
||||||
|
expect(stmt.get("baz")).toEqual({ bar: "baz" });
|
||||||
|
|
||||||
|
// Call without parameters should use last bound value ("baz")
|
||||||
|
expect(stmt.get()).toEqual({ bar: "baz" });
|
||||||
|
|
||||||
|
// Bind a different value
|
||||||
|
expect(stmt.get("foo")).toEqual({ bar: "foo" });
|
||||||
|
|
||||||
|
// Call without parameters should now use "foo"
|
||||||
|
expect(stmt.get()).toEqual({ bar: "foo" });
|
||||||
|
});
|
||||||
|
|
||||||
|
test("Statement.all() uses last bound value when called without parameters", () => {
|
||||||
|
using db = new Database(":memory:");
|
||||||
|
db.run("CREATE TABLE foo (bar TEXT)");
|
||||||
|
db.run("INSERT INTO foo VALUES ('baz')");
|
||||||
|
db.run("INSERT INTO foo VALUES ('foo')");
|
||||||
|
|
||||||
|
using stmt = db.prepare("SELECT * FROM foo WHERE bar = ?");
|
||||||
|
|
||||||
|
// First call without binding returns empty array (no match)
|
||||||
|
expect(stmt.all()).toEqual([]);
|
||||||
|
|
||||||
|
// Bind and get values
|
||||||
|
expect(stmt.all("baz")).toEqual([{ bar: "baz" }]);
|
||||||
|
|
||||||
|
// Call without parameters should use last bound value ("baz")
|
||||||
|
expect(stmt.all()).toEqual([{ bar: "baz" }]);
|
||||||
|
|
||||||
|
// Bind a different value
|
||||||
|
expect(stmt.all("foo")).toEqual([{ bar: "foo" }]);
|
||||||
|
|
||||||
|
// Call without parameters should now use "foo"
|
||||||
|
expect(stmt.all()).toEqual([{ bar: "foo" }]);
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user