Skip to content

sqlite: bind ArrayBuffer #61396

@mike-git374

Description

@mike-git374

Problem

You can bind Buffer or TypedArray (added in #56384) but ArrayBuffer doesn't work:

import { DatabaseSync } from 'node:sqlite';

const db = new DatabaseSync(':memory:');

db.exec('create table t (c)');

const insert = db.prepare('insert into t values (?)');
const select = db.prepare('select * from t');

insert.run(new Uint8Array([ 1, 2, 3 ]));
insert.run(new Uint16Array([ 4, 5, 6 ]));
insert.run(new Uint8Array([ 7, 8, 9 ]).buffer); // ArrayBuffer
insert.run(Buffer.from([ 10, 11, 12 ]));

console.log(select.all());

// [
//   { c: Uint8Array(3) [ 1, 2, 3 ] },
//   { c: Uint8Array(6) [ 4, 0, 5, 0, 6, 0 ] },
//   { c: null },
//   { c: Uint8Array(3) [ 10, 11, 12 ] }
// ]

Related: Boolean should also be allowed to bind, see SQLite bind booleans

Proposal

Allow binding ArrayBuffer, either by directly handling ArrayBuffer if possible, or internally converting to Uint8Array/Buffer if needed

Alternatives

Convert to Uint8Array or Buffer before binding, but this should not be required:

insert.run(Buffer.from(arrayBuffer));

insert.run(new Uint8Array(arrayBuffer));

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestIssues that request new features to be added to Node.js.

    Type

    No type

    Projects

    Status

    Awaiting Triage

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions