var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.upsertCidsForQuery = void 0;
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
var _convertFilterSortToQuery = require("./utils/convertFilterSortToQuery");
var _createUpsertQuery = require("../sqlite-utils/createUpsertQuery");
var _SqliteClient = require("../SqliteClient");
var upsertCidsForQuery = exports.upsertCidsForQuery = function () {
  var _ref2 = (0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee(_ref) {
    var cids, filters, _ref$execute, execute, sort, cidsString, id, query;
    return _regenerator["default"].wrap(function _callee$(_context) {
      while (1) switch (_context.prev = _context.next) {
        case 0:
          cids = _ref.cids, filters = _ref.filters, _ref$execute = _ref.execute, execute = _ref$execute === void 0 ? true : _ref$execute, sort = _ref.sort;
          cidsString = JSON.stringify(cids);
          id = (0, _convertFilterSortToQuery.convertFilterSortToQuery)({
            filters: filters,
            sort: sort
          });
          query = (0, _createUpsertQuery.createUpsertQuery)('channelQueries', {
            cids: cidsString,
            id: id
          });
          _SqliteClient.SqliteClient.logger == null || _SqliteClient.SqliteClient.logger('info', 'upsertCidsForQuery', {
            cids: cidsString,
            execute: execute,
            id: id
          });
          if (!execute) {
            _context.next = 8;
            break;
          }
          _context.next = 8;
          return _SqliteClient.SqliteClient.executeSql.apply(null, query);
        case 8:
          return _context.abrupt("return", [query]);
        case 9:
        case "end":
          return _context.stop();
      }
    }, _callee);
  }));
  return function upsertCidsForQuery(_x) {
    return _ref2.apply(this, arguments);
  };
}();
//# sourceMappingURL=upsertCidsForQuery.js.map