📜  sqlite3 多线程 nodejs - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:03:11.193000             🧑  作者: Mango

代码示例1
const cluster = require('cluster');
const db = new sqlite3.Database(':memory:')

if (cluster.isMaster) {
    console.log(`Master ${process.pid} is running`);
    cluster.fork()
        .on('exit', (worker, code, signal) => {
            console.log(`worker ${worker.process.pid} died`);
        });
    cluster.fork()
        .on('exit', (worker, code, signal) => {
            console.log(`worker ${worker.process.pid} died`);
        });

} else if (cluster.worker.id === 1){
  db.run(QUERY1);
} else {
 db.run(QUERY2);
}