Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3999786

Browse filesBrowse files
Renegade334targos
authored andcommitted
sqlite: allow returning ArrayBufferViews from user-defined functions
PR-URL: #56790 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent e1f86c1 commit 3999786
Copy full SHA for 3999786

File tree

Expand file treeCollapse file tree

3 files changed

+15
-9
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+15
-9
lines changed
Open diff view settings
Collapse file

‎doc/api/sqlite.md‎

Copy file name to clipboardExpand all lines: doc/api/sqlite.md
+7-7Lines changed: 7 additions & 7 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -500,13 +500,13 @@ more data types than SQLite, only a subset of JavaScript types are supported.
500500
Attempting to write an unsupported data type to SQLite will result in an
501501
exception.
502502

503-
| SQLite | JavaScript |
504-
| --------- | -------------------- |
505-
| `NULL` | {null} |
506-
| `INTEGER` | {number} or {bigint} |
507-
| `REAL` | {number} |
508-
| `TEXT` | {string} |
509-
| `BLOB` | {Uint8Array} |
503+
| SQLite | JavaScript |
504+
| --------- | -------------------------- |
505+
| `NULL` | {null} |
506+
| `INTEGER` | {number} or {bigint} |
507+
| `REAL` | {number} |
508+
| `TEXT` | {string} |
509+
| `BLOB` | {TypedArray} or {DataView} |
510510

511511
## `sqlite.constants`
512512

Collapse file

‎src/node_sqlite.cc‎

Copy file name to clipboardExpand all lines: src/node_sqlite.cc
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ class UserDefinedFunction {
213213
} else if (result->IsString()) {
214214
Utf8Value val(isolate, result.As<String>());
215215
sqlite3_result_text(ctx, *val, val.length(), SQLITE_TRANSIENT);
216-
} else if (result->IsUint8Array()) {
216+
} else if (result->IsArrayBufferView()) {
217217
ArrayBufferViewContents<uint8_t> buf(result);
218218
sqlite3_result_blob(ctx, buf.data(), buf.length(), SQLITE_TRANSIENT);
219219
} else if (result->IsBigInt()) {
Collapse file

‎test/parallel/test-sqlite-custom-functions.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-sqlite-custom-functions.js
+7-1Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,13 +274,18 @@ suite('DatabaseSync.prototype.function()', () => {
274274
db.function('retString', () => { return 'foo'; });
275275
db.function('retBigInt', () => { return 5n; });
276276
db.function('retUint8Array', () => { return new Uint8Array([1, 2, 3]); });
277+
db.function('retArrayBufferView', () => {
278+
const arrayBuffer = new Uint8Array([1, 2, 3]).buffer;
279+
return new DataView(arrayBuffer);
280+
});
277281
const stmt = db.prepare(`SELECT
278282
retUndefined() AS retUndefined,
279283
retNull() AS retNull,
280284
retNumber() AS retNumber,
281285
retString() AS retString,
282286
retBigInt() AS retBigInt,
283-
retUint8Array() AS retUint8Array
287+
retUint8Array() AS retUint8Array,
288+
retArrayBufferView() AS retArrayBufferView
284289
`);
285290
assert.deepStrictEqual(stmt.get(), {
286291
__proto__: null,
@@ -290,6 +295,7 @@ suite('DatabaseSync.prototype.function()', () => {
290295
retString: 'foo',
291296
retBigInt: 5,
292297
retUint8Array: new Uint8Array([1, 2, 3]),
298+
retArrayBufferView: new Uint8Array([1, 2, 3]),
293299
});
294300
});
295301

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.