mysql-rewrapped
Version:
A wrapper for MySQL on node to make querying a database as easy as possible
45 lines (44 loc) • 1.71 kB
JavaScript
;
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var Query_1 = require("../Query");
var Update = /** @class */ (function (_super) {
__extends(Update, _super);
function Update(fields) {
var _this = _super.call(this, "UPDATE") || this;
_this.setStatement = "";
_this.setParams = [];
Object.keys(fields).forEach(function (item) {
_this.setStatement += item + " = ?, ";
_this.setParams.push(fields[item]);
});
_this.setStatement = _this.setStatement.substr(0, _this.setStatement.length - 2) + " ";
return _this;
}
Update.prototype.toString = function () {
return (this.type +
" " +
this.tableName +
" SET " +
this.setStatement +
(this.whereStatement !== null ? this.whereStatement : ""));
};
Update.prototype.exec = function (cback) {
this.queryParams = this.setParams.concat(this.whereParams);
_super.prototype.exec.call(this, cback);
};
return Update;
}(Query_1.default));
exports.default = Update;