rename updateOld
This commit is contained in:
parent
41993e61c7
commit
7533a5e7ed
29
db.js
29
db.js
@ -51,7 +51,7 @@ class DB {
|
||||
return await this.execQuery(sql, params);
|
||||
}
|
||||
|
||||
async update(tblName, whereList, fieldList) {
|
||||
async updateOld(tblName, whereList, fieldList) {
|
||||
const params = [];
|
||||
let sql = 'UPDATE `' + tblName + '` SET ';
|
||||
|
||||
@ -70,6 +70,33 @@ class DB {
|
||||
return await this.execScript(sql, params);
|
||||
}
|
||||
|
||||
async update(tblName, whereList, fieldList) {
|
||||
const params = [];
|
||||
let sql = 'UPDATE `' + tblName + '` SET ';
|
||||
|
||||
fieldList.forEach((item, index) => {
|
||||
const suffix = (index + 1 < fieldList.length ? ',': '');
|
||||
if (item[0][0] == '!') {
|
||||
if (typeof item[1] == 'function') {
|
||||
sql += ' `' + item[0].substr(1) + '`=' + item[1]() + suffix;
|
||||
} else {
|
||||
sql += ' `' + item[0].substr(1) + '`=' + item[1] + suffix;
|
||||
}
|
||||
} else {
|
||||
sql += ' `' + item[0] + '`=?' + suffix;
|
||||
params.push(item[1]);
|
||||
}
|
||||
});
|
||||
|
||||
sql += ' WHERE 1=1';
|
||||
whereList.forEach((item, index) => {
|
||||
sql += ' AND ' + item[0] + '=?';
|
||||
params.push(item[1]);
|
||||
});
|
||||
|
||||
return await this.execScript(sql, params);
|
||||
}
|
||||
|
||||
async insert(tblName, fieldList) {
|
||||
const params = [];
|
||||
let sql = 'INSERT INTO `' + tblName + '` (';
|
||||
|
Loading…
x
Reference in New Issue
Block a user