const { query } = require("./dbconnection");
const config = require("../conf/config.json");
const moment = require("moment");

const checkExist = async (dbName, tbName) => {
  const qResut = await query(
    `SELECT 1 AS EXT FROM Information_schema.tables WHERE table_schema = '${dbName}' AND table_name = '${tbName}';`,
  );

  if (qResut.length == 1) return true;
  else return false;
};

const createTable = async (dbName, tbName, tbRefName) => {
  try {
    await query(
      `CREATE TABLE IF NOT EXISTS \`${dbName}\`.${tbName} LIKE \`${dbName}\`.${tbRefName};`,
    );
  } catch (error) {
    console.log(error);
  }
};

module.exports = {
  checkExist,
  createTable,
};
