mirror of
https://github.com/zebrajr/node.git
synced 2025-12-06 00:20:08 +01:00
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>
25 lines
821 B
JavaScript
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
|
|
}
|