transaction.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. 'use strict';
  2. exports.__esModule = true;
  3. var _assign2 = require('lodash/assign');
  4. var _assign3 = _interopRequireDefault(_assign2);
  5. var _transaction = require('../../transaction');
  6. var _transaction2 = _interopRequireDefault(_transaction);
  7. var _inherits = require('inherits');
  8. var _inherits2 = _interopRequireDefault(_inherits);
  9. var _helpers = require('../../helpers');
  10. var helpers = _interopRequireWildcard(_helpers);
  11. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
  12. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  13. var debug = require('debug')('knex:tx');
  14. function Transaction_MySQL2() {
  15. _transaction2.default.apply(this, arguments);
  16. }
  17. (0, _inherits2.default)(Transaction_MySQL2, _transaction2.default);
  18. (0, _assign3.default)(Transaction_MySQL2.prototype, {
  19. query: function query(conn, sql, status, value) {
  20. var t = this;
  21. var q = this.trxClient.query(conn, sql).catch(function (err) {
  22. return err.code === 'ER_SP_DOES_NOT_EXIST';
  23. }, function () {
  24. helpers.warn('Transaction was implicitly committed, do not mix transactions and' + 'DDL with MySQL (#805)');
  25. }).catch(function (err) {
  26. status = 2;
  27. value = err;
  28. t._completed = true;
  29. debug('%s error running transaction query', t.txid);
  30. }).tap(function () {
  31. if (status === 1) t._resolver(value);
  32. if (status === 2) t._rejecter(value);
  33. });
  34. if (status === 1 || status === 2) {
  35. t._completed = true;
  36. }
  37. return q;
  38. }
  39. });
  40. exports.default = Transaction_MySQL2;
  41. module.exports = exports['default'];