OwlCyberSecurity - MANAGER
Edit File: table.controller.js
// controllers/table.controller.js import pool from '../db.js'; export const getAllTables = async (req, res) => { try { const [rows] = await pool.query("SHOW TABLES"); const tableNames = rows.map(row => Object.values(row)[0]); res.json(tableNames); } catch (err) { console.error('Error fetching tables:', err); res.status(500).json({ error: 'Internal server error' }); } }; export const getTableData = async (req, res) => { const tableName = req.params.name; try { const [rows] = await pool.query(`SELECT * FROM ?? LIMIT 100`, [tableName]); res.json(rows); } catch (err) { console.error(`Error fetching data from table ${tableName}:`, err); res.status(500).json({ error: 'Failed to fetch table data' }); } };