node/test/sqlite/worker.js
Bart Louwers d2ff9daf58
sqlite: fix crash session extension callbacks with workers
PR-URL: https://github.com/nodejs/node/pull/59848
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Zeyu "Alex" Yang <himself65@outlook.com>
Reviewed-By: Edy Silva <edigleyssonsilva@gmail.com>
2025-09-23 14:41:39 +00:00

25 lines
821 B
JavaScript

// This worker is used for one of the tests in test-sqlite-session.js
'use strict';
require('../common');
const { parentPort, workerData } = require('worker_threads');
const { DatabaseSync, constants } = require('node:sqlite');
const { changeset, mode, dbPath } = workerData;
const db = new DatabaseSync(dbPath);
const options = {};
if (mode !== constants.SQLITE_CHANGESET_ABORT && mode !== constants.SQLITE_CHANGESET_OMIT) {
throw new Error('Unexpected value for mode');
}
options.onConflict = () => mode;
try {
const result = db.applyChangeset(changeset, options);
parentPort.postMessage({ mode, result, error: null });
} catch (error) {
parentPort.postMessage({ mode, result: null, errorMessage: error.message, errcode: error.errcode });
} finally {
db.close(); // Just to make sure it is closed ASAP
}