Skip to content

Commit

Permalink
兼容 exports.default
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterMu committed Mar 2, 2017
1 parent 0633aa1 commit 3ff26cc
Show file tree
Hide file tree
Showing 12 changed files with 88 additions and 113 deletions.
2 changes: 1 addition & 1 deletion .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"es2015",
"stage-2"
],
"plugins": []
"plugins": ["add-module-exports"]
}
3 changes: 2 additions & 1 deletion dist/lib/dialects/mysql/pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,5 @@ var _class = function () {
return _class;
}();

exports.default = _class;
exports.default = _class;
module.exports = exports['default'];
5 changes: 3 additions & 2 deletions dist/lib/models.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
value: true
});

var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; };
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

Expand Down Expand Up @@ -103,4 +103,5 @@ var _class = function () {
return _class;
}();

exports.default = _class;
exports.default = _class;
module.exports = exports['default'];
168 changes: 68 additions & 100 deletions dist/lib/pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ Object.defineProperty(exports, "__esModule", {
value: true
});

var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; };

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

var _pool = require('./dialects/mysql/pool');
Expand All @@ -14,7 +12,7 @@ var _pool2 = _interopRequireDefault(_pool);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { return step("next", value); }, function (err) { return step("throw", err); }); } } return step("next"); }); }; }
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

Expand Down Expand Up @@ -100,98 +98,67 @@ var _class = function () {
}, {
key: 'query',
value: function () {
var _ref3 = _asyncToGenerator(regeneratorRuntime.mark(function _callee4(key, sql, params, transationConn) {
var _this = this;

var that, _ret;
var _ref3 = _asyncToGenerator(regeneratorRuntime.mark(function _callee3(key, sql, params, transationConn) {
var that, conn, _that;

return regeneratorRuntime.wrap(function _callee4$(_context4) {
return regeneratorRuntime.wrap(function _callee3$(_context3) {
while (1) {
switch (_context4.prev = _context4.next) {
switch (_context3.prev = _context3.next) {
case 0:
that = this;
_context4.prev = 1;
return _context4.delegateYield(regeneratorRuntime.mark(function _callee3() {
var conn, that;
return regeneratorRuntime.wrap(function _callee3$(_context3) {
while (1) {
switch (_context3.prev = _context3.next) {
case 0:
params = params || [];
_context3.t0 = transationConn;

if (_context3.t0) {
_context3.next = 6;
break;
}

_context3.next = 5;
return _this.getConn();

case 5:
_context3.t0 = _context3.sent;

case 6:
conn = _context3.t0;
that = _this;
return _context3.abrupt('return', {
v: new Promise(function (resolve, reject) {
conn._query(sql, params, function (err, results) {
if (!err) {
if (that.config.camelCase) {
results = that.parseCamelCase(results);
}
var errors = that.models.validate(key, results);
if (errors) {
reject(errors);
} else {
resolve(results);
}
} else {
reject(err);
}
if (!transationConn) {
that.releaseConn(conn);
}
});
})
});

case 9:
case 'end':
return _context3.stop();
}
}
}, _callee3, _this);
})(), 't0', 3);
_context3.prev = 1;

case 3:
_ret = _context4.t0;
params = params || [];
_context3.t0 = transationConn;

if (!((typeof _ret === 'undefined' ? 'undefined' : _typeof(_ret)) === "object")) {
_context4.next = 6;
if (_context3.t0) {
_context3.next = 8;
break;
}

return _context4.abrupt('return', _ret.v);
_context3.next = 7;
return this.getConn();

case 6:
_context4.next = 12;
break;
case 7:
_context3.t0 = _context3.sent;

case 8:
_context4.prev = 8;
_context4.t1 = _context4['catch'](1);
conn = _context3.t0;
_that = this;
return _context3.abrupt('return', new Promise(function (resolve, reject) {
conn._query(sql, params, function (err, results) {
if (!err) {
if (_that.config.camelCase) {
results = _that.parseCamelCase(results);
}
var errors = _that.models.validate(key, results);
if (errors) {
reject(errors);
} else {
resolve(results);
}
} else {
reject(err);
}
if (!transationConn) {
_that.releaseConn(conn);
}
});
}));

case 13:
_context3.prev = 13;
_context3.t1 = _context3['catch'](1);

console.error(_context4.t1);
throw new Error(_context4.t1);
console.error(_context3.t1);
throw new Error(_context3.t1);

case 12:
case 17:
case 'end':
return _context4.stop();
return _context3.stop();
}
}
}, _callee4, this, [[1, 8]]);
}, _callee3, this, [[1, 13]]);
}));

function query(_x2, _x3, _x4, _x5) {
Expand All @@ -203,25 +170,25 @@ var _class = function () {
}, {
key: 'beginTransation',
value: function () {
var _ref4 = _asyncToGenerator(regeneratorRuntime.mark(function _callee5() {
var _ref4 = _asyncToGenerator(regeneratorRuntime.mark(function _callee4() {
var conn;
return regeneratorRuntime.wrap(function _callee5$(_context5) {
return regeneratorRuntime.wrap(function _callee4$(_context4) {
while (1) {
switch (_context5.prev = _context5.next) {
switch (_context4.prev = _context4.next) {
case 0:
_context5.next = 2;
_context4.next = 2;
return this._pool.getTransationConn();

case 2:
conn = _context5.sent;
return _context5.abrupt('return', conn);
conn = _context4.sent;
return _context4.abrupt('return', conn);

case 4:
case 'end':
return _context5.stop();
return _context4.stop();
}
}
}, _callee5, this);
}, _callee4, this);
}));

function beginTransation() {
Expand All @@ -233,23 +200,23 @@ var _class = function () {
}, {
key: 'commit',
value: function () {
var _ref5 = _asyncToGenerator(regeneratorRuntime.mark(function _callee6(conn) {
return regeneratorRuntime.wrap(function _callee6$(_context6) {
var _ref5 = _asyncToGenerator(regeneratorRuntime.mark(function _callee5(conn) {
return regeneratorRuntime.wrap(function _callee5$(_context5) {
while (1) {
switch (_context6.prev = _context6.next) {
switch (_context5.prev = _context5.next) {
case 0:
_context6.next = 2;
_context5.next = 2;
return this._pool.commit(conn);

case 2:
return _context6.abrupt('return', _context6.sent);
return _context5.abrupt('return', _context5.sent);

case 3:
case 'end':
return _context6.stop();
return _context5.stop();
}
}
}, _callee6, this);
}, _callee5, this);
}));

function commit(_x6) {
Expand All @@ -261,20 +228,20 @@ var _class = function () {
}, {
key: 'rollback',
value: function () {
var _ref6 = _asyncToGenerator(regeneratorRuntime.mark(function _callee7(conn) {
return regeneratorRuntime.wrap(function _callee7$(_context7) {
var _ref6 = _asyncToGenerator(regeneratorRuntime.mark(function _callee6(conn) {
return regeneratorRuntime.wrap(function _callee6$(_context6) {
while (1) {
switch (_context7.prev = _context7.next) {
switch (_context6.prev = _context6.next) {
case 0:
_context7.next = 2;
_context6.next = 2;
return this._pool.rollback(conn);

case 2:
case 'end':
return _context7.stop();
return _context6.stop();
}
}
}, _callee7, this);
}, _callee6, this);
}));

function rollback(_x7) {
Expand Down Expand Up @@ -377,4 +344,5 @@ var _class = function () {
return _class;
}();

exports.default = _class;
exports.default = _class;
module.exports = exports['default'];
3 changes: 2 additions & 1 deletion dist/lib/rule.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,5 @@ var _class = function () {
return _class;
}();

exports.default = _class;
exports.default = _class;
module.exports = exports['default'];
4 changes: 2 additions & 2 deletions dist/lib/sqlBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var getInsertSql = exports.getInsertSql = function getInsertSql(tableName, data)
};

var getUpdateSql = exports.getUpdateSql = function getUpdateSql(tableName, data) {
var idKey = arguments.length <= 2 || arguments[2] === undefined ? 'id' : arguments[2];
var idKey = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'id';

var sql = '',
params = [],
Expand All @@ -45,7 +45,7 @@ var getUpdateSql = exports.getUpdateSql = function getUpdateSql(tableName, data)
};

var getDelSql = exports.getDelSql = function getDelSql(tableName, id) {
var idKey = arguments.length <= 2 || arguments[2] === undefined ? 'id' : arguments[2];
var idKey = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'id';

var sql = 'delete from ' + tableName + ' where ' + idKey + ' = ?';
return {
Expand Down
3 changes: 2 additions & 1 deletion dist/lib/sqlContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,4 +191,5 @@ var _class = function () {
return _class;
}();

exports.default = _class;
exports.default = _class;
module.exports = exports['default'];
5 changes: 3 additions & 2 deletions dist/nodebatis.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj;

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { return step("next", value); }, function (err) { return step("throw", err); }); } } return step("next"); }); }; }
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

Expand Down Expand Up @@ -373,4 +373,5 @@ var NodeBatis = function () {

NodeBatis.Types = _types2.default;

exports.default = NodeBatis;
exports.default = NodeBatis;
module.exports = exports['default'];
3 changes: 2 additions & 1 deletion dist/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ exports.default = {
MONGOID: MONGOID,
JSON: JSON,
MATCHES: MATCHES
};
};
module.exports = exports['default'];
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"validator": "^5.5.0"
},
"devDependencies": {
"babel-plugin-add-module-exports": "^0.2.1",
"babel-preset-es2015": "^6.6.0",
"babel-preset-stage-2": "^6.5.0",
"babel-register": "^6.8.0",
Expand Down
Loading

0 comments on commit 3ff26cc

Please sign in to comment.