transaction.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 _debug = require('debug');
  10. var _debug2 = _interopRequireDefault(_debug);
  11. var _helpers = require('../../helpers');
  12. var helpers = _interopRequireWildcard(_helpers);
  13. 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; } }
  14. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  15. var debug = (0, _debug2.default)('knex:tx');
  16. function Transaction_MySQL() {
  17. _transaction2.default.apply(this, arguments);
  18. }
  19. (0, _inherits2.default)(Transaction_MySQL, _transaction2.default);
  20. (0, _assign3.default)(Transaction_MySQL.prototype, {
  21. query: function query(conn, sql, status, value) {
  22. var t = this;
  23. var q = this.trxClient.query(conn, sql).catch(function (err) {
  24. return err.errno === 1305;
  25. }, function () {
  26. helpers.warn('Transaction was implicitly committed, do not mix transactions and ' + 'DDL with MySQL (#805)');
  27. }).catch(function (err) {
  28. status = 2;
  29. value = err;
  30. t._completed = true;
  31. debug('%s error running transaction query', t.txid);
  32. }).tap(function () {
  33. if (status === 1) t._resolver(value);
  34. if (status === 2) t._rejecter(value);
  35. });
  36. if (status === 1 || status === 2) {
  37. t._completed = true;
  38. }
  39. return q;
  40. }
  41. });
  42. exports.default = Transaction_MySQL;
  43. module.exports = exports['default'];