From 32e96d8b036905b7593ce880c881b0e5432ab95a Mon Sep 17 00:00:00 2001 From: pjmw9izve <2308014474@qq.com> Date: Mon, 7 Oct 2024 22:25:08 +0800 Subject: [PATCH] ADD file via upload --- delete-table.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 delete-table.js 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 };