const db = 'nikanuss_nikan_ussd'
const user = 'nikanuss_nikan_ussd_user';
const pass = '7G4ZvduRGw7;';


const mysql = require('mysql');


function DoCommand(query, data) {
  return new Promise(function (myResolve, myReject) {
    try {
      const connection = mysql.createConnection({
        host: 'localhost', user: user, password: pass,
        database: db, multipleStatements: true, timezone: 'utc'
      });
      connection.connect(function (err) {
        if (err) setTimeout(() => connection.end(), 100);
      });
      connection.query(query, data, function (error, results, fields) {
        if (error) return myResolve({status: false});
        setTimeout(() => connection.end(), 100);
        if (results.hasOwnProperty('insertId')) return myResolve({id: results.insertId, status: true});
        else return myResolve({results, status: true});
      });
    } catch (e) {
      return myResolve({status: false});
    }
  });
}

// SendSms()


module.exports = {DoCommand};