MCPcopy
hub / github.com/sequelize/sequelize / insertQuery

Method insertQuery

lib/dialects/abstract/query-generator.js:101–262  ·  lib/dialects/abstract/query-generator.js::QueryGenerator.insertQuery

* Returns an insert into command * * @param {string} table * @param {object} valueHash attribute value pairs * @param {object} modelAttributes * @param {object} [options] * * @private

(table, valueHash, modelAttributes, options)

Source from the content-addressed store, hash-verified

99 * @private
100 */
101 insertQuery(table, valueHash, modelAttributes, options) {
102 options = options || {};
103 _.defaults(options, this.options);
104
105 const modelAttributeMap = {};
106 const bind = [];
107 const fields = [];
108 const returningModelAttributes = [];
109 const values = [];
110 const quotedTable = this.quoteTable(table);
111 const bindParam = options.bindParam === undefined ? this.bindParam(bind) : options.bindParam;
112 let query;
113 let valueQuery = class="st">'';
114 let emptyQuery = class="st">'';
115 let outputFragment = class="st">'';
116 let returningFragment = class="st">'';
117 let identityWrapperRequired = false;
118 let tmpTable = class="st">''; class="cm">//tmpTable declaration for trigger
119
120 if (modelAttributes) {
121 _.each(modelAttributes, (attribute, key) => {
122 modelAttributeMap[key] = attribute;
123 if (attribute.field) {
124 modelAttributeMap[attribute.field] = attribute;
125 }
126 });
127 }
128
129 if (this._dialect.supports[class="st">'DEFAULT VALUES']) {
130 emptyQuery += class="st">' DEFAULT VALUES';
131 } else if (this._dialect.supports[class="st">'VALUES ()']) {
132 emptyQuery += class="st">' VALUES ()';
133 }
134
135 if (this._dialect.supports.returnValues && options.returning) {
136 const returnValues = this.generateReturnValues(modelAttributes, options);
137
138 returningModelAttributes.push(...returnValues.returnFields);
139 returningFragment = returnValues.returningFragment;
140 tmpTable = returnValues.tmpTable || class="st">'';
141 outputFragment = returnValues.outputFragment || class="st">'';
142 }
143
144 if (_.get(this, [class="st">'sequelize', class="st">'options', class="st">'dialectOptions', class="st">'prependSearchPath']) || options.searchPath) {
145 class="cm">// Not currently supported with search path (requires output of multiple queries)
146 options.bindParam = false;
147 }
148
149 if (this._dialect.supports.EXCEPTION && options.exception) {
150 class="cm">// Not currently supported with bind parameters (requires output of multiple queries)
151 options.bindParam = false;
152 }
153
154 valueHash = Utils.removeNullValuesFromHash(valueHash, this.options.omitNull);
155 for (const key in valueHash) {
156 if (Object.prototype.hasOwnProperty.call(valueHash, key)) {
157 const value = valueHash[key];
158 fields.push(this.quoteIdentifier(key));

Callers 5

insertMethod · 0.80
upsertMethod · 0.80
upsertMethod · 0.80
upsertMethod · 0.80
insert.test.jsFile · 0.80

Calls 7

quoteTableMethod · 0.95
bindParamMethod · 0.95
generateReturnValuesMethod · 0.95
quoteIdentifierMethod · 0.95
escapeMethod · 0.95
formatMethod · 0.95
getMethod · 0.65

Tested by

no test coverage detected