var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.upsertPoll = void 0;
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
var _mapPollToStorable = require("../mappers/mapPollToStorable");
var _createUpsertQuery = require("../sqlite-utils/createUpsertQuery");
var _SqliteClient = require("../SqliteClient");
var upsertPoll = exports.upsertPoll = function () {
  var _ref2 = (0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee(_ref) {
    var _ref$execute, execute, poll, queries, storablePoll;
    return _regenerator["default"].wrap(function _callee$(_context) {
      while (1) switch (_context.prev = _context.next) {
        case 0:
          _ref$execute = _ref.execute, execute = _ref$execute === void 0 ? true : _ref$execute, poll = _ref.poll;
          queries = [];
          storablePoll = (0, _mapPollToStorable.mapPollToStorable)(poll);
          queries.push((0, _createUpsertQuery.createUpsertQuery)('poll', storablePoll));
          _SqliteClient.SqliteClient.logger == null || _SqliteClient.SqliteClient.logger('info', 'upsertPoll', {
            poll: storablePoll
          });
          if (!execute) {
            _context.next = 8;
            break;
          }
          _context.next = 8;
          return _SqliteClient.SqliteClient.executeSqlBatch(queries);
        case 8:
          return _context.abrupt("return", queries);
        case 9:
        case "end":
          return _context.stop();
      }
    }, _callee);
  }));
  return function upsertPoll(_x) {
    return _ref2.apply(this, arguments);
  };
}();
//# sourceMappingURL=upsertPoll.js.map