Skip to content

Commit e01aa90

Browse files
committed
sqlite: support ArrayBuffer and TypedArray in StatementSync
1 parent ca3c8f1 commit e01aa90

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

doc/api/sqlite.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ added: v22.5.0
326326

327327
* `namedParameters` {Object} An optional object used to bind named parameters.
328328
The keys of this object are used to configure the mapping.
329-
* `...anonymousParameters` {null|number|bigint|string|Buffer|Uint8Array} Zero or
329+
* `...anonymousParameters` {null|number|bigint|string|Buffer|Uint8Array|TypedArray|DataView} Zero or
330330
more values to bind to anonymous parameters.
331331
* Returns: {Array} An array of objects. Each object corresponds to a row
332332
returned by executing the prepared statement. The keys and values of each
@@ -358,7 +358,7 @@ added: v22.5.0
358358

359359
* `namedParameters` {Object} An optional object used to bind named parameters.
360360
The keys of this object are used to configure the mapping.
361-
* `...anonymousParameters` {null|number|bigint|string|Buffer|Uint8Array} Zero or
361+
* `...anonymousParameters` {null|number|bigint|string|Buffer|Uint8Array|TypedArray|DataView} Zero or
362362
more values to bind to anonymous parameters.
363363
* Returns: {Object|undefined} An object corresponding to the first row returned
364364
by executing the prepared statement. The keys and values of the object
@@ -378,7 +378,7 @@ added: v23.4.0
378378

379379
* `namedParameters` {Object} An optional object used to bind named parameters.
380380
The keys of this object are used to configure the mapping.
381-
* `...anonymousParameters` {null|number|bigint|string|Buffer|Uint8Array} Zero or
381+
* `...anonymousParameters` {null|number|bigint|string|Buffer|Uint8Array|TypedArray|DataView} Zero or
382382
more values to bind to anonymous parameters.
383383
* Returns: {Iterator} An iterable iterator of objects. Each object corresponds to a row
384384
returned by executing the prepared statement. The keys and values of each
@@ -397,7 +397,7 @@ added: v22.5.0
397397

398398
* `namedParameters` {Object} An optional object used to bind named parameters.
399399
The keys of this object are used to configure the mapping.
400-
* `...anonymousParameters` {null|number|bigint|string|Buffer|Uint8Array} Zero or
400+
* `...anonymousParameters` {null|number|bigint|string|Buffer|Uint8Array|TypedArray|DataView} Zero or
401401
more values to bind to anonymous parameters.
402402
* Returns: {Object}
403403
* `changes`: {number|bigint} The number of rows modified, inserted, or deleted

src/node_sqlite.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -930,7 +930,8 @@ bool StatementSync::BindParams(const FunctionCallbackInfo<Value>& args) {
930930
int anon_idx = 1;
931931
int anon_start = 0;
932932

933-
if (args[0]->IsObject() && !args[0]->IsUint8Array()) {
933+
if (args[0]->IsObject() && !args[0]->IsUint8Array() &&
934+
!args[0]->IsTypedArray() && !args[0]->IsArrayBuffer()) {
934935
Local<Object> obj = args[0].As<Object>();
935936
Local<Context> context = obj->GetIsolate()->GetCurrentContext();
936937
Local<Array> keys;
@@ -1035,7 +1036,8 @@ bool StatementSync::BindValue(const Local<Value>& value, const int index) {
10351036
statement_, index, *val, val.length(), SQLITE_TRANSIENT);
10361037
} else if (value->IsNull()) {
10371038
r = sqlite3_bind_null(statement_, index);
1038-
} else if (value->IsUint8Array()) {
1039+
} else if (value->IsUint8Array() || value->IsArrayBufferView() ||
1040+
value->IsArrayBuffer()) {
10391041
ArrayBufferViewContents<uint8_t> buf(value);
10401042
r = sqlite3_bind_blob(
10411043
statement_, index, buf.data(), buf.length(), SQLITE_TRANSIENT);

0 commit comments

Comments
 (0)