Skip to content

Commit

Permalink
fix(ext/node): represent sqlite blob as Uint8Array (#27889)
Browse files Browse the repository at this point in the history
  • Loading branch information
littledivy authored Jan 31, 2025
1 parent 08cc221 commit 057f257
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
8 changes: 4 additions & 4 deletions ext/node/ops/sqlite/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,10 @@ impl StatementSync {
let size = ffi::sqlite3_column_bytes(self.inner, index);
let value =
std::slice::from_raw_parts(value as *const u8, size as usize);
let value =
v8::ArrayBuffer::new_backing_store_from_vec(value.to_vec())
.make_shared();
v8::ArrayBuffer::with_backing_store(scope, &value).into()
let bs = v8::ArrayBuffer::new_backing_store_from_vec(value.to_vec())
.make_shared();
let ab = v8::ArrayBuffer::with_backing_store(scope, &bs);
v8::Uint8Array::new(scope, ab, 0, size as _).unwrap().into()
}
ffi::SQLITE_NULL => v8::null(scope).into(),
_ => v8::undefined(scope).into(),
Expand Down
11 changes: 10 additions & 1 deletion tests/unit_node/sqlite_test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright 2018-2025 the Deno authors. MIT license.
import { DatabaseSync } from "node:sqlite";
import { assertEquals, assertThrows } from "@std/assert";
import { assert, assertEquals, assertThrows } from "@std/assert";

Deno.test("[node/sqlite] in-memory databases", () => {
const db1 = new DatabaseSync(":memory:");
Expand Down Expand Up @@ -63,3 +63,12 @@ Deno.test("[node/sqlite] StatementSync read bigints are supported", () => {
stmt.setReadBigInts(true);
assertEquals(stmt.get(), { key: 1n, __proto__: null });
});

Deno.test("[node/sqlite] StatementSync blob are Uint8Array", () => {
const db = new DatabaseSync(":memory:");
const obj = db.prepare("select cast('test' as blob)").all();

assertEquals(obj.length, 1);
const row = obj[0] as Record<string, Uint8Array>;
assert(row["cast('test' as blob)"] instanceof Uint8Array);
});

0 comments on commit 057f257

Please sign in to comment.