rename updateOld

This commit is contained in:
aozhiwei 2022-10-20 21:05:19 +08:00
parent 41993e61c7
commit 7533a5e7ed

29
db.js
View File

@ -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 + '` (';