centralized
v0.1.2
Published
[](https://github.com/WebReflection/centralized/actions) [ {
const stmt = this.connection.prepare(sql);
return await stmt.exec(...values);
},
// the init method executes once only in the main thread ...
init() {
// ... and it can pollute its context with values
this.connection = db.connect({user, pass, stuff});
}
});
if (cluster.isWorker) {
// this will return the result from the db
const result = await appHelper.query(
'SELECT * FROM table WHERE thing = ?',
'cool'
);
console.log(result);
}
else {
// perform the query all over the place
for (let {length} = cpus(), i = 0; i < length; i++)
cluster.fork();
}And that's all folks 🥳
