diff --git a/delete-table.js b/delete-table.js new file mode 100644 index 0000000..3ed710c --- /dev/null +++ b/delete-table.js @@ -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 };