-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
Expand file tree
/
Copy pathworker.js
More file actions
24 lines (20 loc) · 821 Bytes
/
worker.js
File metadata and controls
24 lines (20 loc) · 821 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// 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
}