parent
1c143b8e77
commit
32e96d8b03
@ -0,0 +1,22 @@
|
||||
const pool = require('../db');
|
||||
|
||||
async function deleteTable(req, res) {
|
||||
const { tableName } = req.body; // 从请求体中获取表名
|
||||
let connection;
|
||||
|
||||
try {
|
||||
connection = await pool.getConnection();
|
||||
await connection.query(`DROP TABLE IF EXISTS ??`, [tableName]); // 删除表
|
||||
connection.release();
|
||||
res.json({ message: `表 ${tableName} 已被成功删除` });
|
||||
} catch (error) {
|
||||
console.error('删除表失败:', error);
|
||||
res.status(500).json({ error: '删除表失败' });
|
||||
} finally {
|
||||
if (connection) {
|
||||
connection.release();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { deleteTable };
|
Loading…
Reference in new issue