UNPKG

mysql-rewrapped

Version:

A wrapper for MySQL on node to make querying a database as easy as possible

56 lines (55 loc) 2.04 kB
"use strict"; 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 Insert = /** @class */ (function (_super) { __extends(Insert, _super); /** * * @param fields - list of fields to insert formatted as {field: value} */ function Insert(fields) { var _this = _super.call(this, "INSERT") || this; _this.valuesStatement = ""; _this.fields = Object.keys(fields).join(", "); _this.valuesParams = []; _this.values(fields); return _this; } /** * * @param fields - fields to insert formatted as {field: value} * @returns {Insert} */ Insert.prototype.values = function (fields) { var _this = this; var rowParsed = Array(Object.keys(fields).length + 1).join("?, "); rowParsed = rowParsed.substr(0, rowParsed.length - 2); Object.keys(fields).forEach(function (item) { _this.valuesParams.push(fields[item]); }); this.valuesStatement = rowParsed; return this; }; Insert.prototype.toString = function () { return "INSERT INTO " + this.tableName + " (" + this.fields + ") VALUES (" + this.valuesStatement + ")"; }; Insert.prototype.exec = function (cback) { this.queryParams = this.valuesParams; _super.prototype.exec.call(this, cback); }; return Insert; }(Query_1.default)); exports.default = Insert;