const query = require("../db.js");
const { toCamelCase } = require("./utils.js");

const listTables = async (req, res) => {
  try {
    const result = await query(`SELECT * FROM pg_tables WHERE schemaname = 'public'`);
    const tablenames = result.rows.map(row => toCamelCase(row.tablename));
    res.status(200).json(tablenames);
  
  } catch (err) {
    console.error("Error handling the request:", err);
    res.status(500).json({ error: "An error occurred while processing the request" });
  }
};

module.exports = listTables;
