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")) { if (SQL.toUpperCase().startsWith("SELECT")) {
db.all(SQL, [], (err, rows) => { db.all(SQL, [], (err, rows) => {
if (err) { if (err) {
console.log("A"); reject("ERROR: fetching data: " + err + err.stack);
reject("ERROR: fetching data: ", err.message);
} }
console.log("B", rows);
resolve(rows); resolve(rows);
}); });
} else { } else {
db.run(SQL, (err) => { db.run(SQL, (err) => {
if (err) { if (err) {
reject("ERROR: inserting row: ", err.message); reject("ERROR: running statement: (" + SQL + ") " + err + err.stack);
} }
resolve(true); 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 () => { /* let main = async () => {
query('insert into log (message) values (\'Outside\')'); query('insert into log (message) values (\'Outside\')');
let rows = null; let rows = null;
@@ -56,20 +64,12 @@ let close = () => {
} catch (ex) { } catch (ex) {
console.error('Error', ex); console.error('Error', ex);
} }
console.re
process.stdin.resume();//so the program will not close instantly
} }
main(); */ 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 = { module.exports = {
query query

Binary file not shown.