sqlQuery Conversion : add update, insert, delete to s.knexQuery

+ change option tableName to table
add-archived-and-accountType-columns
Moe 2020-07-08 22:38:32 -07:00
parent b02311386b
commit b7db2ecfe9
2 changed files with 30 additions and 11 deletions

View File

@ -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

View File

@ -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"%']
]