mirror of
https://github.com/nodejs/node.git
synced 2026-11-09 15:11:11 -05:00
Rename the DatabaseSync and StatementSync classes to Database and Statement, and the internal DatabaseSyncLimits helper to DatabaseLimits. The old names are kept as aliases of the new classes and are Documentation-only deprecated (DEP0210, DEP0211). Assisted-by: Claude Code Signed-off-by: Guilherme Araújo <arauujogui@gmail.com> PR-URL: https://github.com/nodejs/node/pull/65988 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
123 lines
4.1 KiB
JavaScript
123 lines
4.1 KiB
JavaScript
'use strict';
|
|
const { skipIfSQLiteMissing } = require('../common');
|
|
skipIfSQLiteMissing();
|
|
const { Database } = require('node:sqlite');
|
|
const { suite, test } = require('node:test');
|
|
|
|
const arrayBuffer = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]).buffer;
|
|
const sharedArrayBuffer = new SharedArrayBuffer(8);
|
|
const typedArrayOnSharedArrayBuffer = new Uint8Array(sharedArrayBuffer);
|
|
typedArrayOnSharedArrayBuffer.set([1, 2, 3, 4, 5, 6, 7, 8]);
|
|
|
|
const TypedArrays = [
|
|
['Int8Array', Int8Array],
|
|
['Uint8Array', Uint8Array],
|
|
['Uint8ClampedArray', Uint8ClampedArray],
|
|
['Int16Array', Int16Array],
|
|
['Uint16Array', Uint16Array],
|
|
['Int32Array', Int32Array],
|
|
['Uint32Array', Uint32Array],
|
|
['Float32Array', Float32Array],
|
|
['Float64Array', Float64Array],
|
|
['BigInt64Array', BigInt64Array],
|
|
['BigUint64Array', BigUint64Array],
|
|
['DataView', DataView],
|
|
];
|
|
|
|
suite('Statement with TypedArray/DataView', () => {
|
|
for (const [displayName, TypedArray] of TypedArrays) {
|
|
test(displayName, (t) => {
|
|
const db = new Database(':memory:');
|
|
t.after(() => { db.close(); });
|
|
db.exec('CREATE TABLE test (data BLOB)');
|
|
// insert
|
|
{
|
|
const stmt = db.prepare('INSERT INTO test VALUES (?)');
|
|
stmt.run(new TypedArray(arrayBuffer));
|
|
}
|
|
// select all
|
|
{
|
|
const stmt = db.prepare('SELECT * FROM test');
|
|
const row = stmt.get();
|
|
t.assert.ok(row.data instanceof Uint8Array);
|
|
t.assert.strictEqual(row.data.length, 8);
|
|
t.assert.deepStrictEqual(row.data, new Uint8Array(arrayBuffer));
|
|
}
|
|
// query
|
|
{
|
|
const stmt = db.prepare('SELECT * FROM test WHERE data = ?');
|
|
const rows = stmt.all(new TypedArray(arrayBuffer));
|
|
t.assert.strictEqual(rows.length, 1);
|
|
t.assert.ok(rows[0].data instanceof Uint8Array);
|
|
t.assert.strictEqual(rows[0].data.length, 8);
|
|
t.assert.deepStrictEqual(rows[0].data, new Uint8Array(arrayBuffer));
|
|
}
|
|
});
|
|
}
|
|
});
|
|
|
|
suite('Statement with ArrayBuffer and SharedArrayBuffer', () => {
|
|
const buffers = [
|
|
['ArrayBuffer', arrayBuffer],
|
|
['SharedArrayBuffer', sharedArrayBuffer],
|
|
];
|
|
|
|
for (const [displayName, buffer] of buffers) {
|
|
test(`${displayName} - anonymous binding`, (t) => {
|
|
const db = new Database(':memory:');
|
|
t.after(() => { db.close(); });
|
|
db.exec('CREATE TABLE test (data BLOB)');
|
|
// insert
|
|
{
|
|
const stmt = db.prepare('INSERT INTO test VALUES (?)');
|
|
stmt.run(buffer);
|
|
}
|
|
// select all
|
|
{
|
|
const stmt = db.prepare('SELECT * FROM test');
|
|
const row = stmt.get();
|
|
t.assert.ok(row.data instanceof Uint8Array);
|
|
t.assert.strictEqual(row.data.length, 8);
|
|
t.assert.deepStrictEqual(row.data, new Uint8Array(arrayBuffer));
|
|
}
|
|
// query
|
|
{
|
|
const stmt = db.prepare('SELECT * FROM test WHERE data = ?');
|
|
const rows = stmt.all(buffer);
|
|
t.assert.strictEqual(rows.length, 1);
|
|
t.assert.ok(rows[0].data instanceof Uint8Array);
|
|
t.assert.strictEqual(rows[0].data.length, 8);
|
|
t.assert.deepStrictEqual(rows[0].data, new Uint8Array(arrayBuffer));
|
|
}
|
|
});
|
|
|
|
test(`${displayName} - named binding (object)`, (t) => {
|
|
const db = new Database(':memory:');
|
|
t.after(() => { db.close(); });
|
|
db.exec('CREATE TABLE test (data BLOB)');
|
|
// insert
|
|
{
|
|
const stmt = db.prepare('INSERT INTO test VALUES ($data)');
|
|
stmt.run({ '$data': buffer });
|
|
}
|
|
// select all
|
|
{
|
|
const stmt = db.prepare('SELECT * FROM test');
|
|
const row = stmt.get();
|
|
t.assert.ok(row.data instanceof Uint8Array);
|
|
t.assert.strictEqual(row.data.length, 8);
|
|
t.assert.deepStrictEqual(row.data, new Uint8Array(arrayBuffer));
|
|
}
|
|
// query
|
|
{
|
|
const stmt = db.prepare('SELECT * FROM test WHERE data = $data');
|
|
const rows = stmt.all({ '$data': buffer });
|
|
t.assert.strictEqual(rows.length, 1);
|
|
t.assert.ok(rows[0].data instanceof Uint8Array);
|
|
t.assert.strictEqual(rows[0].data.length, 8);
|
|
t.assert.deepStrictEqual(rows[0].data, new Uint8Array(arrayBuffer));
|
|
}
|
|
});
|
|
}
|
|
});
|