"use strict";

Object.defineProperty(exports, "__esModule", {
    value: true
});
exports.Connection = undefined;

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

var _stackerjsUtils = require("stackerjs-utils");

var _FileAdapter = require("./FileAdapter");

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Connection = function () {
    function Connection() {
        _classCallCheck(this, Connection);
    }

    _createClass(Connection, null, [{
        key: "query",
        value: function query(_query) {
            if (!this.isConnected()) this.connect();

            return this.pool.execute(_query).then(function (result) {
                return result;
            });
        }
    }, {
        key: "connect",
        value: function connect() {
            this.pool = new _FileAdapter.FileAdapter(this.parameters.host, this.parameters.name);
        }
    }, {
        key: "isConnected",
        value: function isConnected() {
            return this.pool instanceof _FileAdapter.FileAdapter;
        }
    }, {
        key: "disconnect",
        value: function disconnect() {
            this.pool = null;
        }
    }]);

    return Connection;
}();

exports.Connection = Connection;

Connection.parameters = {
    host: _stackerjsUtils.Config.get("db.host"),
    name: _stackerjsUtils.Config.get("db.name")
};
Connection.pool;