diff --git a/libs/sql.js b/libs/sql.js index bc3df06a..892f6c7d 100644 --- a/libs/sql.js +++ b/libs/sql.js @@ -62,18 +62,30 @@ module.exports = function(s,config){ .asCallback(callback) }, 4); const knexQuery = (options) => { + if(config.debugLog === true){ + s.debugLog('s.knexQuery QUERY',options) + } // options = { // action: "", // columns: "", - // tableName: "" + // table: "" // } var response switch(options.action){ case'select': - response = s.databaseEngine.select(...options.columns) + if(!options.columns)options.columns = '*' + response = s.databaseEngine.select(...options.columns).from(options.table) + break; + case'update': + response = s.databaseEngine(options.table).update(options.update) + break; + case'delete': + response = s.databaseEngine(options.table).del() + break; + case'insert': + response = s.databaseEngine(options.table).insert(options.insert) break; } - response.from(options.tableName) if(options.where){ var didOne = false; options.where.forEach((where) => { @@ -82,7 +94,9 @@ module.exports = function(s,config){ didOne = true whereIsArray ? response.where(...where) : response.where(where) }else if(where.length === 4){ - switch(where[0]){ + const separator = where[0] + '' + where.shift() + switch(separator){ case'and': whereIsArray ? response.andWhere(...where) : response.andWhere(where) break; @@ -95,6 +109,11 @@ module.exports = function(s,config){ } }) } + if(options.update || options.insert){ + response.asCallback(function(err,r) { + if(err)console.log(err) + }) + } return response } s.knexQuery = knexQuery diff --git a/libs/startup.js b/libs/startup.js index 24f6e357..cee5c69b 100644 --- a/libs/startup.js +++ b/libs/startup.js @@ -46,7 +46,7 @@ module.exports = function(s,config,lang,io){ s.knexQuery({ action: "select", columns: "*", - tableName: "Monitors", + table: "Monitors", }).asCallback(function(err,monitors) { foundMonitors = monitors if(err){s.systemLog(err)} @@ -122,7 +122,7 @@ module.exports = function(s,config,lang,io){ s.knexQuery({ action: "select", columns: "*", - tableName: "Videos", + table: "Videos", where: [ ['ke','=',user.ke], ['status','!=',0], @@ -131,7 +131,7 @@ module.exports = function(s,config,lang,io){ s.knexQuery({ action: "select", columns: "*", - tableName: "Timelapse Frames", + table: "Timelapse Frames", where: [ ['ke','=',user.ke], ] @@ -139,7 +139,7 @@ module.exports = function(s,config,lang,io){ s.knexQuery({ action: "select", columns: "*", - tableName: "Files", + table: "Files", where: [ ['ke','=',user.ke], ] @@ -209,7 +209,7 @@ module.exports = function(s,config,lang,io){ s.knexQuery({ action: "select", columns: "*", - tableName: "Cloud Videos", + table: "Cloud Videos", where: [ ['ke','=',user.ke], ['status','!=',0], @@ -237,7 +237,7 @@ module.exports = function(s,config,lang,io){ s.knexQuery({ action: "select", columns: "*", - tableName: "Cloud Timelapse Frames", + table: "Cloud Timelapse Frames", where: [ ['ke','=',user.ke], ] @@ -328,7 +328,7 @@ module.exports = function(s,config,lang,io){ s.knexQuery({ action: "select", columns: "*", - tableName: "Users", + table: "Users", where: [ ['details','NOT LIKE','%"sub"%'] ]