-
Notifications
You must be signed in to change notification settings - Fork 0
/
incs.js
46 lines (41 loc) · 1.03 KB
/
incs.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
"use strict";
module.exports = {
/*
parseSQL function
- sqlObj is the json-sql object
EX: values = { var: "string" }
query = '"This" is a $var' =>
return: '`This` is a string'
*/
parseSQL: function(sqlObj){
let output = sqlObj.query.replace(/"/g,'`');
Object.keys(sqlObj.values).forEach((objectKey, index)=>{
output = output.replace('$'+objectKey,'"'+sqlObj.values[objectKey]+'"');
});
output = output.replace(/T00:00:00Z/g,' 00:00:00'); //For timestamp
return output;
},
/*
insertSQL function
- args = {
mysql: mysql,
jsonSql: jsonSql,
values: values,
table: table
}
*/
insertFromGithubSQL: function(args){
if(args.values.length > -1){
let sql = args.jsonSql.build({
type: 'insert',
table: args.table,
values: args.values,
});
console.log(this.parseSQL(sql));
args.mysql.query(this.parseSQL(sql),(err,result)=>{
console.log(result);
console.error(err);
});
}
}
}