From 4af3a383555a39f6ab65e6c849f9b6cdeb10ca87 Mon Sep 17 00:00:00 2001 From: Alexander Blair Date: Sat, 11 Feb 2017 11:52:30 -0800 Subject: [PATCH] Moving loop counter to inside of the sql select, and adding an extra abort stage. --- sql_sync/sql_sync.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sql_sync/sql_sync.js b/sql_sync/sql_sync.js index fe1f73a..e7e39a4 100644 --- a/sql_sync/sql_sync.js +++ b/sql_sync/sql_sync.js @@ -14,9 +14,13 @@ global.schema = JSON.parse(sql_schema); let loopCount = 0; let updatedCount = 0; global.schema.forEach(function(entry){ - loopCount += 1; global.mysql.query("SELECT * FROM config WHERE module = ? AND item = ?", [entry.module, entry.item]).then(function(rows){ + loopCount += 1; if (rows.length > 0){ + if(loopCount === global.schema.length){ + console.log("Updated SQL schema with "+updatedCount+" new rows! Exiting!"); + process.exit(); + } return; } updatedCount += 1;