fixup the calss on the go from learnings on OptiWiz

This commit is contained in:
Joe Tretter
2018-09-18 16:13:19 -05:00
parent 008a4df31e
commit f6bb4e241d
2 changed files with 14 additions and 14 deletions

View File

@@ -15,16 +15,14 @@ let query = (SQL) => {
if (SQL.toUpperCase().startsWith("SELECT")) {
db.all(SQL, [], (err, rows) => {
if (err) {
console.log("A");
reject("ERROR: fetching data: ", err.message);
reject("ERROR: fetching data: " + err + err.stack);
}
console.log("B", rows);
resolve(rows);
});
} else {
db.run(SQL, (err) => {
if (err) {
reject("ERROR: inserting row: ", err.message);
reject("ERROR: running statement: (" + SQL + ") " + err + err.stack);
}
resolve(true);
});
@@ -43,6 +41,16 @@ let close = () => {
});
}
let exitHandler = (eventType) => {
console.log("DB-Cleaning up (" + eventType + ")");
close().then(process.exit);
}
// make sure we close the DB in case the process ends.
[`exit`, `SIGINT`, `SIGUSR1`, `SIGUSR2`, `uncaughtException`, `SIGTERM`].forEach((eventType) => {
process.on(eventType, exitHandler.bind(null, eventType));
})
/* let main = async () => {
query('insert into log (message) values (\'Outside\')');
let rows = null;
@@ -56,20 +64,12 @@ let close = () => {
} catch (ex) {
console.error('Error', ex);
}
console.re
process.stdin.resume();//so the program will not close instantly
}
main(); */
let exitHandler = (eventType) => {
console.log("DB-Cleaning up (" + eventType + ")");
close();
}
// make sure we close the DB in case the process ends.
[`exit`, `SIGINT`, `SIGUSR1`, `SIGUSR2`, `uncaughtException`, `SIGTERM`].forEach((eventType) => {
process.on(eventType, exitHandler.bind(null, eventType));
})
module.exports = {
query