import { DatabaseSync } from "node:sqlite";
import { workerData, parentPort } from "node:worker_threads";
const { dbPath, mode, ms, tag } = workerData;
const opts = mode === "ctor" ? { timeout: ms } : {};
const d = new DatabaseSync(dbPath, opts);
if (mode === "pragma") d.exec(`PRAGMA busy_timeout = ${ms}`);
let ok = 0, locks = 0;
const end = Date.now() + 3000;
while (Date.now() < end) {
    try { d.prepare("UPDATE t SET v=? WHERE id=?").run(`${tag}-${ok}`, ok % 200); ok++; }
    catch (e) { if (/locked|busy/i.test(e.message)) locks++; else throw e; }
}
d.close();
parentPort.postMessage({ ok, locks });
