mirror of
https://github.com/denoland/deno.git
synced 2025-12-23 08:48:24 +00:00
fix(ext/node): represent sqlite blob as Uint8Array (#27889)
This commit is contained in:
parent
08cc22105f
commit
057f257052
2 changed files with 14 additions and 5 deletions
|
|
@ -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(),
|
||||
|
|
|
|||
|
|
@ -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:");
|
||||
|
|
@ -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);
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue