transaction.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. 'use strict';
  2. exports.__esModule = true;
  3. var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
  4. var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
  5. var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');
  6. var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
  7. var _inherits2 = require('babel-runtime/helpers/inherits');
  8. var _inherits3 = _interopRequireDefault(_inherits2);
  9. var _debug = require('debug');
  10. var _debug2 = _interopRequireDefault(_debug);
  11. var _transaction = require('../../transaction');
  12. var _transaction2 = _interopRequireDefault(_transaction);
  13. var _helpers = require('../../helpers');
  14. var helpers = _interopRequireWildcard(_helpers);
  15. 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; } }
  16. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  17. var debug = (0, _debug2.default)('knex:tx');
  18. var Transaction_Maria = function (_Transaction) {
  19. (0, _inherits3.default)(Transaction_Maria, _Transaction);
  20. function Transaction_Maria() {
  21. (0, _classCallCheck3.default)(this, Transaction_Maria);
  22. return (0, _possibleConstructorReturn3.default)(this, _Transaction.apply(this, arguments));
  23. }
  24. Transaction_Maria.prototype.query = function query(conn, sql, status, value) {
  25. var t = this;
  26. var q = this.trxClient.query(conn, sql).catch(function (err) {
  27. return err.code === 1305;
  28. }, function () {
  29. helpers.warn('Transaction was implicitly committed, do not mix transactions and ' + 'DDL with MariaDB (#805)');
  30. }).catch(function (err) {
  31. status = 2;
  32. value = err;
  33. t._completed = true;
  34. debug('%s error running transaction query', t.txid);
  35. }).tap(function () {
  36. if (status === 1) t._resolver(value);
  37. if (status === 2) t._rejecter(value);
  38. });
  39. if (status === 1 || status === 2) {
  40. t._completed = true;
  41. }
  42. return q;
  43. };
  44. return Transaction_Maria;
  45. }(_transaction2.default);
  46. exports.default = Transaction_Maria;
  47. module.exports = exports['default'];