'use strict';
'use warning';

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;

var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));

var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));

var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

var _Config = require("../../Config");

var _lodash = _interopRequireDefault(require("lodash"));

/**
 * Functions Fot Class Mysql Database In Framework
 * All Right Reserved
 * **/
var MySQL = /*#__PURE__*/function () {
  /***
   * @returns {number}
   * @constructor
   */

  /***
   * @returns {number}
   * @constructor
   */

  /***
   *
   * @returns {number}
   */

  /**
   *
   * @param {JSON} options
   */
  function MySQL(options) {
    (0, _classCallCheck2["default"])(this, MySQL);
    this.options = _lodash["default"].extend(_Config.Server.DBConfig, options);
  }

  (0, _createClass2["default"])(MySQL, [{
    key: "Create",
    value: function Create(DBInstance) {
      this.DBInstance = DBInstance;

      var MySQLEngine = require("mysql");

      return DBInstance === MySQL.MYSQL_POOL_CLUSTER ? MySQLEngine.createPoolCluster(this.options) : DBInstance === MySQL.MYSQL_POOL ? MySQLEngine.createPool(this.options) : DBInstance === MySQL.MYSQL_CREATECONNECTION ? MySQLEngine.createConnection(this.options) : MySQLEngine.createConnection(this.options);
    }
  }, {
    key: "rawQuery",
    value:
    /**
     *
     * @param {Connection|Pool|boolean} MySQLConnect
     * @param SQLString
     * @param Callback
     */
    function rawQuery(MySQLConnect, SQLString, Callback) {
      /** Declaration Of Variable **/
      if (this.DBInstance === MySQL.MYSQL_POOL) {
        MySQLConnect.getConnection(function (error, connection) {
          if (error) throw error;
          connection.query(SQLString, function (error, results, fields) {
            connection.release();
            if (error) throw error;
            Callback(error, results, fields);
          });
        });
      } else if (this.DBInstance === MySQL.MYSQL_POOL_CLUSTER) {} else if (this.DBInstance === MySQL.MYSQL_CREATECONNECTION) {
        MySQLConnect.connect(function (error) {
          if (error) throw error;
          MySQLConnect.query(SQLString, function (error, results, fields) {
            MySQLConnect.end();
            if (error) throw error;
            Callback(error, results, fields);
          });
        });
      }
    }
  }, {
    key: "setDatabase",
    value: function setDatabase() {}
  }]);
  return MySQL;
}();

(0, _defineProperty2["default"])(MySQL, "MYSQL_CREATECONNECTION", 1);
(0, _defineProperty2["default"])(MySQL, "MYSQL_POOL_CLUSTER", 2);
(0, _defineProperty2["default"])(MySQL, "MYSQL_POOL", 3);
var _default = MySQL;
exports["default"] = _default;
//# sourceMappingURL=index.js.map