* 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)
| 138 | * @private |
| 139 | */ |
| 140 | insertQuery(table, valueHash, modelAttributes, options) { |
| 141 | options = options || {}; |
| 142 | _.defaults(options, this.options); |
| 143 | |
| 144 | const modelAttributeMap = {}; |
| 145 | const bind = options.bind || []; |
| 146 | const fields = []; |
| 147 | const returningModelAttributes = []; |
| 148 | const returnTypes = []; |
| 149 | const values = []; |
| 150 | const quotedTable = this.quoteTable(table); |
| 151 | const bindParam = options.bindParam === undefined ? this.bindParam(bind) : options.bindParam; |
| 152 | const returnAttributes = []; |
| 153 | let query; |
| 154 | let valueQuery = ''; |
| 155 | let emptyQuery = ''; |
| 156 | let outputFragment = ''; |
| 157 | let returningFragment = ''; |
| 158 | let identityWrapperRequired = false; |
| 159 | let tmpTable = ''; //tmpTable declaration for trigger |
| 160 | |
| 161 | if (modelAttributes) { |
| 162 | _.each(modelAttributes, (attribute, key) => { |
| 163 | modelAttributeMap[key] = attribute; |
| 164 | if (attribute.field) { |
| 165 | modelAttributeMap[attribute.field] = attribute; |
| 166 | } |
| 167 | }); |
| 168 | } |
| 169 | |
| 170 | if (this._dialect.supports['DEFAULT VALUES']) { |
| 171 | emptyQuery += ' DEFAULT VALUES'; |
| 172 | } else if (this._dialect.supports['VALUES ()']) { |
| 173 | emptyQuery += ' VALUES ()'; |
| 174 | } |
| 175 | |
| 176 | if ((this._dialect.supports.returnValues || this._dialect.supports.returnIntoValues) && options.returning) { |
| 177 | const returnValues = this.generateReturnValues(modelAttributes, options); |
| 178 | |
| 179 | returningModelAttributes.push(...returnValues.returnFields); |
| 180 | // Storing the returnTypes for dialects that need to have returning into bind information for outbinds |
| 181 | if (this._dialect.supports.returnIntoValues) { |
| 182 | returnTypes.push(...returnValues.returnTypes); |
| 183 | } |
| 184 | returningFragment = returnValues.returningFragment; |
| 185 | tmpTable = returnValues.tmpTable || ''; |
| 186 | outputFragment = returnValues.outputFragment || ''; |
| 187 | } |
| 188 | |
| 189 | if (_.get(this, ['sequelize', 'options', 'dialectOptions', 'prependSearchPath']) || options.searchPath) { |
| 190 | // Not currently supported with search path (requires output of multiple queries) |
| 191 | options.bindParam = false; |
| 192 | } |
| 193 | |
| 194 | if (this._dialect.supports.EXCEPTION && options.exception) { |
| 195 | // Not currently supported with bind parameters (requires output of multiple queries) |
| 196 | options.bindParam = false; |
| 197 | } |
no test coverage detected