|
|
|
@ -31,6 +31,7 @@ app.post('/insert', (req, res) => {
|
|
|
|
|
|
|
|
|
|
// 构建SQL插入语句
|
|
|
|
|
const placeholders = columns.map(() => '?'); // 原数组映射为新数组,新数组的每个元素均为问号,使用问号作为占位符
|
|
|
|
|
//需要用这种方式来赋值,不然字符串的双引号会丢失
|
|
|
|
|
const sql = `INSERT INTO \`${table}\` (${columns.join(', ')}) VALUES (${placeholders.join(', ')})`;
|
|
|
|
|
|
|
|
|
|
// 执行SQL插入语句
|
|
|
|
@ -69,9 +70,10 @@ app.post('/modify', (req, res) => {
|
|
|
|
|
const { table,id,columns, values } = req.body; // 从请求体获取数据
|
|
|
|
|
|
|
|
|
|
// 构建SQL插入语句
|
|
|
|
|
const placeholder = columns.map((element,index) => element + '=' + values[index]).join(',');
|
|
|
|
|
const placeholder = columns.map(() => '?'); // 原数组映射为新数组,新数组的每个元素均为问号,使用问号作为占位符
|
|
|
|
|
const placeholders = columns.map((element,index) => element + '=' + placeholder[index]).join(',');
|
|
|
|
|
//组合成 name1=value1,name2=value2,name3=value3......的形式
|
|
|
|
|
const sql = `UPDATE \`${table}\` ${placeholder} where id = ${id}`;
|
|
|
|
|
const sql = `UPDATE \`${table}\` SET ${placeholders} where id = ${id}`;
|
|
|
|
|
|
|
|
|
|
// 执行SQL插入语句
|
|
|
|
|
pool.query(sql, values, (error, results, fields) => {
|
|
|
|
|