aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2023-06-06 23:52:23 -0700
committerGravatar GitHub <noreply@github.com> 2023-06-06 23:52:23 -0700
commit7e296a1adc929a933f5287285752d241dfd135e3 (patch)
tree4a0bf3ccc5b3983c650c1d6d95cfbaa618fbe06b
parentb9a705f84b9f07e365ba1e5cc6afc8b0bb3a7906 (diff)
downloadbun-7e296a1adc929a933f5287285752d241dfd135e3.tar.gz
bun-7e296a1adc929a933f5287285752d241dfd135e3.tar.zst
bun-7e296a1adc929a933f5287285752d241dfd135e3.zip
[breaking][bun:sqlite] `.values()` returns `[]` instead of `null` for queries returning 0 results (#3219)
Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
-rw-r--r--packages/bun-types/sqlite.d.ts9
-rw-r--r--src/bun.js/bindings/sqlite/JSSQLStatement.cpp3
-rw-r--r--test/js/bun/sqlite/sqlite.test.js8
3 files changed, 18 insertions, 2 deletions
diff --git a/packages/bun-types/sqlite.d.ts b/packages/bun-types/sqlite.d.ts
index 8066aa475..e1b8adcd0 100644
--- a/packages/bun-types/sqlite.d.ts
+++ b/packages/bun-types/sqlite.d.ts
@@ -579,7 +579,9 @@ declare module "bun:sqlite" {
/**
* Execute the prepared statement and return the results as an array of arrays.
*
- * This is a little faster than {@link all}.
+ * In Bun v0.6.7 and earlier, this method returned `null` if there were no
+ * results instead of `[]`. This was changed in v0.6.8 to align
+ * more with what people expect.
*
* @param params optional values to bind to the statement. If omitted, the statement is run with the last bound values or no parameters if there are none.
*
@@ -595,12 +597,15 @@ declare module "bun:sqlite" {
*
* stmt.values("foo");
* // => [['foo']]
+ *
+ * stmt.values("not-found");
+ * // => []
* ```
*
* The following types can be used when binding parameters:
*
* | JavaScript type | SQLite type |
- * | -------------- | ----------- |
+ * | ---------------|-------------|
* | `string` | `TEXT` |
* | `number` | `INTEGER` or `DECIMAL` |
* | `boolean` | `INTEGER` (1 or 0) |
diff --git a/src/bun.js/bindings/sqlite/JSSQLStatement.cpp b/src/bun.js/bindings/sqlite/JSSQLStatement.cpp
index a561057fe..a6855fd19 100644
--- a/src/bun.js/bindings/sqlite/JSSQLStatement.cpp
+++ b/src/bun.js/bindings/sqlite/JSSQLStatement.cpp
@@ -1417,6 +1417,9 @@ JSC_DEFINE_HOST_FUNCTION(jsSQLStatementExecuteStatementFunctionRows, (JSC::JSGlo
result = resultArray;
}
+ } else if (status == SQLITE_DONE && columnCount != 0) {
+ // breaking change in Bun v0.6.8
+ result = JSC::constructEmptyArray(lexicalGlobalObject, nullptr, 0);
}
if (UNLIKELY(status != SQLITE_DONE && status != SQLITE_OK)) {
diff --git a/test/js/bun/sqlite/sqlite.test.js b/test/js/bun/sqlite/sqlite.test.js
index a23c2f037..faa7d5015 100644
--- a/test/js/bun/sqlite/sqlite.test.js
+++ b/test/js/bun/sqlite/sqlite.test.js
@@ -503,6 +503,14 @@ it("latin1 supplement chars", () => {
greeting: "¿Qué sucedió?",
},
]);
+
+ expect(db.query("SELECT * FROM foo").values()).toEqual([
+ [1, "Welcome to bun!"],
+ [2, "Español"],
+ [3, "¿Qué sucedió?"],
+ ]);
+ expect(db.query("SELECT * FROM foo WHERE id > 9999").all()).toEqual([]);
+ expect(db.query("SELECT * FROM foo WHERE id > 9999").values()).toEqual([]);
});
describe("Database.run", () => {