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

Method insertQuery

lib/dialects/abstract/query-generator.js:101–262  ·  view source on GitHub ↗

* 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 = '';
114 let emptyQuery = '';
115 let outputFragment = '';
116 let returningFragment = '';
117 let identityWrapperRequired = false;
118 let tmpTable = ''; //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['DEFAULT VALUES']) {
130 emptyQuery += ' DEFAULT VALUES';
131 } else if (this._dialect.supports['VALUES ()']) {
132 emptyQuery += ' 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 || '';
141 outputFragment = returnValues.outputFragment || '';
142 }
143
144 if (_.get(this, ['sequelize', 'options', 'dialectOptions', 'prependSearchPath']) || options.searchPath) {
145 // 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 // 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