const { query } = require("../mods/dbconnection");

const tableExists = async (tableSchema, tableName) => {
    const rows = await query(
        `
        SELECT COUNT(*) AS cnt
        FROM INFORMATION_SCHEMA.TABLES
        WHERE TABLE_SCHEMA = ?
          AND TABLE_NAME = ?
        `,
        [tableSchema, tableName]
    );

    return Number(rows[0]?.cnt ?? 0) > 0;
};

module.exports = {
    tableExists,
};